放送受信機に通知を開始させることはできますか?
このコードを試しましたが、機能しません。
通知は作成されますが、クリックしても何も起こりません。
注:notificationIntentをMyBroadcastReceiver.classからアクティビティ(MainActivity.classなど)に変更すると、正常に機能します。
通知の作成:
NotificationManager notificationManager = (NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);
int notificationIconId = XXXXXX
Notification notification = new Notification(
notificationIconId,
XXXXXX,
System.currentTimeMillis()
);
CharSequence contentTitle = XXXXXXX
CharSequence contentText = XXXXXX
Intent notificationIntent = new Intent(context,MyBroadcastReceiver.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notificationManager.notify(1,notification);
これがBroadcastReceiverです
public static class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
/*
*/
}
}
AndroidManifest.xmlの内部
<receiver android:name=".MyBroadcastReceiver" />