如何从BroadcastReceiver的解雇通知?通知、BroadcastReceiver

由网友(颜值超标)分享简介:如何火从BroadcastReceiver的通知(不能用大多数方法,并不能使用本)?我需要它从DB我已经做到了信息打开一个活动,但现在必须在忽略了最低的工作方式,我不能用这个how to fire notification from BroadcastReceiver (can't use most methods...

如何火从BroadcastReceiver的通知(不能用大多数方法,并不能使用本)? 我需要它从DB我已经做到了信息打开一个活动,但现在必须在忽略了最低的工作方式,我不能用这个

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"

推荐答案

的onReceive 方法,你会得到一个上下文对象。所以用它来获得 NotificationManager 和消防您的通知。

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);
}

这是活动服务上下文推导。这就是为什么,在许多(或所有)的上下文的实例方法,你可以使用。如果这是你的话,那么你可以使用上下文您在收到的onReceive

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.

阅读全文

相关推荐

最新文章