android o广播注册,AlarmManager和BroadcastReceiver的LocalNotification未...

在SDK 26之前,我已经在机器人上运行了本地通知

但是在Android O中我收到了以下警告,广播接收器没有被解雇.

W/BroadcastQueue: Background execution not allowed: receiving Intent { act=package.name.action.LOCAL_NOTIFICATION cat=[com.category.LocalNotification] flg=0x14 (has extras) } to package.name/com.category.localnotifications.LocalNotificationReceiver

从我所看到的广播接收器在Android O中受到更多限制,但如果是这样,即使主要活动没有运行,我应该如何安排广播?

我应该使用服务而不是接收器吗?

这是AlarmManager启动代码:

public void Schedule(String aID, String aTitle, String aBody, int aNotificationCode, long aEpochTime)

{

Bundle lExtras = new Bundle();

lExtras.putInt("icon", f.getDefaultIcon());

lExtras.putString("title", aTitle);

lExtras.putString("message", aBody);

lExtras.putString("id", aID);

lExtras.putInt("requestcode", aNotificationCode);

Intent lIntent =

new Intent(LocalNotificationScheduler.ACTION_NAME)

.addCategory(NotificationsUtils.LocalNotifCategory)

.putExtras(lExtras);

PendingIntent lPendIntent = PendingIntent.getBroadcast(f.getApplicationContext(), aNotificationCode,

lIntent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager lAlarmMgr = (AlarmManager) f.getSystemService(Context.ALARM_SERVICE);

lAlarmMgr.set(AlarmManager.RTC, 1000, lPendIntent);

}

这是接收者代码:

public class LocalNotificationReceiver extends BroadcastReceiver {

public static native void nativeReceiveLocalNotification (String aID, String aTitle, String aMessage, boolean aOnForeground );

/** This method receives the alarms set by LocalNotificationScheduler,

* notifies the CAndroidNotifications c++ class, and (if needed) ships a notification banner

*/

@Override

public void onReceive(Context aContext, Intent aIntent)

{

Toast.makeText(context, text, duration).show();

}

}

Android清单:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值