如何使用 react-native-firebase 默认启用浮动通知?

How to enabled floating notification by default with react-native-firebase?

晕,我使用 react-native-firebase 在 react-native 中推送通知,运行 在模拟器上很好,但在某些设备上 浮动通知、锁屏通知和声音 默认禁用。

如何在应用安装时强制启用这些设置?

我没有尝试,但首先您可以使用支持库中的 NotificationManagerCompat.areNotificationsEnabled() 检查通知是否被禁用。 API 19 以下的版本将 return 为真(启用通知)。

然后如果通知被禁用,您可以警告您的用户并开始通知设置,例如 :

Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");

//for Android 5-7
intent.putExtra("app_package", getPackageName());
intent.putExtra("app_uid", getApplicationInfo().uid);

// for Android 8 and above
intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());

startActivity(intent);