小弟有个问题,android里面的自定义广播为什么注册不上呢,在AndroidManifest里面已经写了<receiver>.public class Lianxi_custom_receiverActivity extends Activity
{ /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick_Send(View v)
{
Intent broadcastIntent=new Intent("zhou.disk.ABC4");
broadcastIntent.addCategory("zhou.disk.mycategory4");
broadcastIntent.putExtra("name", "zhouyu");
this.sendBroadcast(broadcastIntent);
Toast.makeText(this, "广播发送成功", Toast.LENGTH_LONG).show();
}
}public class CustomReceiver2 extends BroadcastReceiver
{ @Override
public void onReceive(Context context, Intent intent)
{
if ("zhou.disk.ABC4".equals(intent.getAction()))
{
String name = intent.getStringExtra("name");
Toast.makeText(context, name, Toast.LENGTH_LONG).show(); } }}<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="zhou.disk"
android:versionCode="1"
android:versionName="1.0" > <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".Lianxi_custom_receiverActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".CustomReceiver2">
<intent-filter>
<action android:name="zhou.disk.ABC4" />
<category android:name="zhou.disk.mycategory4" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
{ /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick_Send(View v)
{
Intent broadcastIntent=new Intent("zhou.disk.ABC4");
broadcastIntent.addCategory("zhou.disk.mycategory4");
broadcastIntent.putExtra("name", "zhouyu");
this.sendBroadcast(broadcastIntent);
Toast.makeText(this, "广播发送成功", Toast.LENGTH_LONG).show();
}
}public class CustomReceiver2 extends BroadcastReceiver
{ @Override
public void onReceive(Context context, Intent intent)
{
if ("zhou.disk.ABC4".equals(intent.getAction()))
{
String name = intent.getStringExtra("name");
Toast.makeText(context, name, Toast.LENGTH_LONG).show(); } }}<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="zhou.disk"
android:versionCode="1"
android:versionName="1.0" > <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".Lianxi_custom_receiverActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".CustomReceiver2">
<intent-filter>
<action android:name="zhou.disk.ABC4" />
<category android:name="zhou.disk.mycategory4" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
解决方案 »
- Android 项目 本人想做个记录旅程,希望是以时间轴的方式,不知有没有源码
- 有关osmdroid的例子
- 4.0的gallery开机扫描文件问题
- Android关于应用程序归类问题
- cannot be resolved or is not a field 等待高手解决,谢谢
- 关于gallery的问题
- android mediaplayer对rmvb等格式如何解码
- 求助service播放器,activity,service与widget间的通信
- 要学习Android 希望能推荐本好书
- 调用GLSurfaceview ,在固定位置出错;
- 菜鸟问关于桌面文件夹的问题
- handleMessage里面更新ListView内容
这个去掉试试
代码里也不要加