public class ReactFireBaseMessagingService extends FirebaseMessagingService {
private NotificationUtils notificationUtils;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Check if Notn are Enabled?
if (getPrefernceHelperInstace().getBoolean(getApplicationContext(),
ENABLE_NOTIFICATION, true)) {
//Show Notification
} else {
Log.e(TAG, "ReactFireBaseMessagingService: Notifications Are Disabled by User");
}
}
3 回答
无法禁用其他应用的通知 . 您只能控制自己的应用生成的通知 .
Turn off notifications of an app programatically on Android
Android: is it possible to remove a system-managed notification programmatically?
You can do it with shared preferences.
您可以在共享首选项中设置通知设置,如果收到任何消息,您可以决定是否显示通知 .
Snippet下面是ReactNative,但您也可以使用相同的Native Apps
稍后在Message服务类中
请参阅代码SNippet
https://github.com/hiteshsahu/react-native-fcm-android/blob/master/android/app/src/main/java/com/hitesh_sahu/fcm/service/ReactFireBaseMessagingService.java
不,你不能,也许在root设备上,但这是另一个故事......