一、声明Activity 内部 BroadcastReceiver ()
public static class Alarmreceivers extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if(intent.getAction().equals("com.test.testtest")) { Log.v("afasfasf", "ddddd"); } } }
AndroidManifest.xml 文件中声明
<receiver android:name=".TestActivity$Alarmreceivers" > ($符合前是在哪个Activity,后面是声明定义的类的名字 )
<intent-filter>
<action android:name="com.test.testtest" />
</intent-filter>
</receiver>
注意:如果BroadcastReceiver在Activity内部使用,定义的类一定要是static 的,否则会不起作用