如何从BroadcastReceiver的解雇通知? [英] how to fire notification from BroadcastReceiver?
问题描述
如何火从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
.
这篇关于如何从BroadcastReceiver的解雇通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!