问题
how to fire notification from BroadcastReceiver (can't use most methods and can't use "this")? I need it to open a activity with info from the DB I already did it but now must of the methods dosen't work and I cant use "this"
回答1:
In the onReceive method you get a Context object. So use it to get the NotificationManager and fire your notification.
public void onReceive(Context ctx, Intent intent) {
NotificationManager nm = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE);
//Create the notification here.
nm.notify(NOTIFICATION_ID, notification);
}
An Activity and a Service are derived from Context. That's why, in many (or all) of the instance methods of a context, you can use this. If that's your case, then you can use the Context you receive in onReceive.
来源:https://stackoverflow.com/questions/8280275/how-to-fire-notification-from-broadcastreceiver