Firebase on Android - I want to disable firebase notifications on Android client

前端 未结 5 1813
忘掉有多难
忘掉有多难 2020-12-16 13:38

I\'m using Firebase console to send notifications to users. However I want to let users disable notifications. How can I disable them?

I am able to handle (and stop)

5条回答
  •  心在旅途
    2020-12-16 14:26

    You can handle all push events from all difference services (with Firebase). First create YouUniversalFCM extends WakefulBroadcastReceiver

    For example:

    public class YourUniversalFCM extends WakefulBroadcastReceiver {
    
        private static final String ACTION_REGISTRATION
            = "com.google.android.c2dm.intent.REGISTRATION";
        private static final String ACTION_RECEIVE
            = "com.google.android.c2dm.intent.RECEIVE";
    
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            for (String key : intent.getExtras().keySet()) {
                Log.d(
                        "TAG",
                        "{UniversalFCM}->onReceive: key->"
                                + key + ", value->" + intent.getExtras().get(key)
                );
            }
            switch (action) {
                case ACTION_REGISTRATION:
                    // TODO: 2016-08-06
                    break;
    
                case ACTION_RECEIVE:
                    // TODO: 2016-08-06
                    break;
    
                default:
            }
    
            abortBroadcast();
        }
    }
    

    Next in AndroidManifest.xml

    
    
    
    
    
        ...
    
        
            
                
                
                
            
        
    
    
    

    Replace YOUR_PACKAGE by the package of your app. That's all. If you want to subscribe for another push service, you must be add YourTokenService

    public class YourTokenService extends FirebaseInstanceIdService {
        @Override
        public void onTokenRefresh() {
            String refreshedToken = FirebaseInstanceId.getInstance().getToken();
            L.d(TokenService.class, "onTokenRefresh() Refreshed token: " + refreshedToken);
            // TODO: 2016-08-06
            super.onTokenRefresh();
        }
    }
    

    And declared in AndroidManifest.xml

    
        
            
        
    
    

提交回复
热议问题