Is it possible to have a notification start a broadcast receiver?
I tried this code but it doesnt work.
Notification is created but when I click on it nothing happens.
NOTE: When I change the notificationIntent to point from MyBroadcastReceiver.class to an activity (like MainActivity.class) it works fine.
Notification creation:
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);
Here is the BroadcastReceiver
public static class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
/*
*/
}
}
Inside AndroidManifest.xml
<receiver android:name=".MyBroadcastReceiver" />