说简单点 28 Android O 8.0 需要动态注册,不能隐式开启,所谓的隐,就是tmd清单文件注册中的action,intent可以使用action来跳转4大组件
google 既然要求了,我们就按照要求来
Intent intent = new Intent();
intent.putExtra("receiverinfo", new Gson().toJson(info));
intent.putExtra("type", type);
intent.putExtra("pushTarget", info.getPushTarget());
intent.setAction(PushTargetManager.ACTION);
//Android O 8.0 之后限制了隐式广播的接收,需要主动注册接收器 23 6.0
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
context.sendBroadcast(intent);
} else {
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
PushBroadcastReceiverIml refreshTokenBroadcastReceiver = new PushBroadcastReceiverIml();
IntentFilter intentFilter = new IntentFilter();
intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
intentFilter.addAction(PushTargetManager.ACTION); //添加action
localBroadcastManager.registerReceiver(refreshTokenBroadcastReceiver, intentFilter); //注册本地广播
localBroadcastManager.sendBroadcast(intent);
}
看明白了你吗
网友评论