Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use FirebaseInstanceId.getInstance().deleteInstanceId()?

I want to delete my FireBaseInstance with

FirebaseInstanceId.getInstance().deleteInstanceId() 

I use a try/catch block but i get this error:

> W/System.err: java.io.IOException: MAIN_THREAD W/System.err:     at
> com.google.firebase.iid.zzd.zzb(Unknown Source) W/System.err:     at
> com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId(Unknown
> Source) W/System.err:     at
> package.class.onCreate(DatenLadenActivity.java:57)
> W/System.err:     at
> android.app.Activity.performCreate(Activity.java:6272) W/System.err:  
> at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
> W/System.err:     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
> W/System.err:     at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
> W/System.err:     at
> android.app.ActivityThread.access$900(ActivityThread.java:157)
> W/System.err:     at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
> W/System.err:     at
> android.os.Handler.dispatchMessage(Handler.java:102) W/System.err:    
> at android.os.Looper.loop(Looper.java:148) W/System.err:     at
> android.app.ActivityThread.main(ActivityThread.java:5525)
> W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
> W/System.err:     at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
> W/System.err:     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

Thanks for your answers :)

like image 701
Johannes Avatar asked Dec 10 '16 09:12

Johannes


People also ask

How do I get FirebaseInstanceId?

For an FCM registration token, use FirebaseMessaging. getToken() instead. Returns the ID and automatically generated token for this Firebase project. This generates an Instance ID if it does not exist yet, which starts periodically sending information to the Firebase backend (see getId() ).

How can I get FCM registration token?

You need to call sendRegistrationToServer() method which will update token on server, if you are sending push notifications from server. UPDATE: New Firebase token is generated ( onTokenRefresh() is called) when: The app deletes Instance ID.

How do I get firebase instance ID in flutter?

To retrieve the FirebaseInstanceId you need to implement the Firebase In-App messaging SDK and make sure your app connects to Firebase. Once the app is connected to Firebase it will add the FirebaseInstanceId to the Android log once the App is run.

What is FCM token used for?

On initial startup of your app, the FCM SDK generates a registration token for the client app instance. This is the token that you must include in targeted send requests from the API, or add to topic subscriptions for targeting topics.


1 Answers

deleteInstanceId() is a blocking call. It cannot be called on the main thread. If you only need to call it for development and testing, you can use a simple Thread:

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        FirebaseInstanceId.getInstance().deleteInstanceId();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
like image 187
Bob Snyder Avatar answered Sep 21 '22 16:09

Bob Snyder