<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fk.lbroadcastreceiver" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 注释下面代码,则Broadcast改为手动注册注销 -->
<receiver
android:name=".LReceiver"
android:enabled="true"
android:exported="true" >
</receiver>
</application>
</manifest>
2. Receiver代码
public class LReceiver extends BroadcastReceiver {
public LReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
//throw new UnsupportedOperationException("Not yet implemented");
System.out.println("接收器L 收到了消息:" + intent.getStringExtra("msg"));
}
}