反应原生推送通知在Android 8.1中无效(API级别27)

问题描述 投票:0回答:2

在我的本机应用程序中,我尝试使用此库react-native-push-notification处理预定的语言环境通知,它在运行Android API 25以下的设备中工作正常,所以问题出现在android Oreo版本中,我尝试了很多解决方案,比如使用频道并向该频道添加通知,但没有结果,请帮助!

我的反应原生版本:

  • react-native-cli:2.0.1
  • 反应原生:0.58.5

来自android项目:

    buildToolsVersion = "28.0.2"
    minSdkVersion = 16
    compileSdkVersion = 28
    targetSdkVersion = 27
    supportLibVersion = "28.0.0"
android react-native android-8.0-oreo localnotification react-native-push-notification
2个回答
2
投票

我花了好几天寻找解决方案后才解决了这个问题!

转到android项目中的react-native-push-notification库文件并进行一些更改here

来自line 572To line

将这些行替换为:

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);
}

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();
    }
© www.soinside.com 2019 - 2024. All rights reserved.