android里面的自定义广播为什么注册不上呢
小弟有个问题,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> --------------------编程问答-------------------- 把<category android:name="zhou.disk.mycategory4" />
这个去掉试试
代码里也不要加
补充:移动开发 , Android