I'm posting questions about Android firebase Please

Asked 2 years ago, Updated 2 years ago, 121 views

Hello, I am applying the alarm push through firebase. It's nothing but I'm raising it like this because I'm having a problem getting the Token price. I've been getting the alarm But I'm trying to get Token's value through the service and save it on the server, but I'm not sure if I'm good enough about the service. Log value doesn't come in at all I'm lost for a while Please.

First of all, the manifest.

<service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <service android:name=".MyFirebaseInstanceIDService"
            android:exported="true">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
    //Inside the application.
</application>

Service source to get Token value.

public class MyFirebaseInstanceIDService extensionsFirebaseInstanceIdService{
    private static final String TAG = "MyFirebaseIIDService";
    @Override
    public void onTokenRefresh()
    {
        // // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);
        // // TODO: Implement this method to send any registration to your app's servers.
        sendRegistrationToServer(refreshedToken);
    }

    public void sendRegistrationToServer(String token)
    {
        OkHttpClient client = new OkHttpClient();
        RequestBody body = new FormBody.Builder()
                .add("Token", token)
                .build();
        Log.d(TAG,"Body : " +body);

        Request request = new Request.Builder()
                .url ("Applicable URL")
                .post(body)
                .build();

        try {
            client.newCall(request).execute();
        } } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

And I put this source in the contentview on the main screen.

FirebaseMessaging.getInstance().subscribeToTopic("test");
 FirebaseInstanceId.getInstance().getToken();

Is there anything wrong? Thank you for reading this long comment

android firebase service

2022-09-22 20:13

1 Answers

Did you solve it? I had the same symptoms, but the token value was coded only when I first built it. If you delete and reinstall the builder app, you can get a token.

Is it too late to answer? ^ ^ ^


2022-09-22 20:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.