这应该相当容易,但我无法触发广播接收器的 onReceive 方法。详情如下:
App B 提供了一个广播接收器。显现:
<receiver android:name=".MyNotificationReceiver">
<intent-filter>
<action android:name="com.go.foo.A_ACTION" />
</intent-filter>
</receiver>
爪哇:
public class MyNotificationReceiver extends BroadcastReceiver {
private final String TAG= "MyNotificationReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "this is not shown" , Toast.LENGTH_LONG).show();
}
}
App A 是 Broadcast Sender App:
爪哇
Intent intent = new Intent();
intent.setAction("com.go.foo.A_ACTION");
sendBroadcast(intent);
Log.d(TAG, "broadcast intent sent...");
我可以看到发送广播但接收者的 onReceive() 回调没有被触发的日志语句。难道我做错了什么?