如何从BroadcastReceiver的解雇通知? [英] how to fire notification from BroadcastReceiver?

查看:95
本文介绍了如何从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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆