在我的react本机应用程序中,我尝试使用此库react-native-push-notification处理计划的区域设置通知,它在运行低于25的android API的设备中正常工作,因此问题出现在android Oreo版本中,我尝试了很多解决方案,例如使用频道并向该频道添加通知,但没有结果,请帮助!!!
我的本机版本 :
来自android项目:
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
答案 0 :(得分:1)
我花了几天时间寻找解决方案后才自己解决了这个问题!
转到react-native-push-notification库的android项目中的文件,并进行here的一些更改
将这些行替换为:
NotificationChannel mChannel = manager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
if (mChannel == null) {
mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Channel name", NotificationManager.IMPORTANCE_MAX);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
manager.createNotificationChannel(mChannel);
}
答案 1 :(得分:0)
反应本机推送通知在> = o中不起作用...
在MAinActivity.java中添加频道
public void onResume() {
super.onResume();
NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel("channelID", "channelName", importance);
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
nMgr.createNotificationChannel(notificationChannel);
}
nMgr.cancelAll();
}