没有刷新令牌firebase android

没有刷新令牌firebase android,第1张

概述我在firebase中获取刷新令牌时遇到了麻烦.我已经完成了文档并完全遵循了android的步骤.在我的日志中,我发现firebase连接成功.不知道为什么我没有获得实例令牌.我处于初始阶段并尝试在logcat中获取令牌.<manifestxmlns:android="http://schemas.android.com/apkes/android"

我在firebase中获取刷新令牌时遇到了麻烦.我已经完成了文档并完全遵循了android的步骤.在我的日志中,我发现firebase连接成功.不知道为什么我没有获得实例令牌.我处于初始阶段并尝试在logcat中获取令牌.

<manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="com.project.application"    androID:versionCode="1"    androID:versionname="1.0" >    <uses-sdk        androID:minSdkVersion="9"        androID:targetSdkVersion="17" />    <uses-permission androID:name="androID.permission.INTERNET" />    <uses-permission androID:name="androID.permission.GET_ACCOUNTS" />    <uses-permission androID:name="androID.permission.VIBRATE" />    <uses-permission androID:name="com.Google.androID.c2dm.permission.RECEIVE" />    <application        androID:allowBackup="false"        androID:icon="@drawable/icon"        androID:label="@string/app_name" >        <activity            androID:name=".Projectname"            androID:configChanges="keyboard|keyboardHIDden|orIEntation|screenSize"            androID:icon="@drawable/icon"            androID:label="@string/app_name"            androID:theme="@androID:style/theme.light.NoTitlebar">             <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>            <Meta-data                androID:name="com.Google.androID.gms.version"                androID:value="@integer/Google_play_services_version" />        </activity>        <service            androID:name=".MyInstanceIDListenerService">            <intent-filter>                <action androID:name="com.Google.firebase.INSTANCE_ID_EVENT" />            </intent-filter>        </service>        <service            androID:name=".MyFirebaseInstanceIDService">            <intent-filter>                <action androID:name="com.Google.firebase.INSTANCE_ID_EVENT"/>            </intent-filter>        </service>           </application></manifest>    public class MyInstanceIDListenerService  extends FirebaseInstanceIDService{        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);        sendRegistrationToServer(refreshedToken);    } public class MyFirebaseMessagingService extends FirebaseMessagingService {private static final String TAG = "MyFirebaseMsgService";@OverrIDepublic voID onMessageReceived(RemoteMessage remoteMessage) {    // Todo(developer): Handle FCM messages here.    Log.d(TAG, "From: " + remoteMessage.getFrom());    String messageBody = null;    // Check if message contains a data payload.    if (remoteMessage.getData().size() > 0) {        Log.d(TAG, "Message data payload: " + remoteMessage.getData());    }    if (remoteMessage.getNotification() != null) {        messageBody = remoteMessage.getNotification().getbody();        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getbody());    }    sendNotification(messageBody);}private voID sendNotification(String messageBody) {    Intent intent = new Intent(this, SplashActivity.class);    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_top);    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,            PendingIntent.FLAG_ONE_SHOT);    Uri defaultSoundUri= ringtoneManager.getDefaultUri(ringtoneManager.TYPE_NOTIFICATION);    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)            .setSmallicon(R.drawable.ic_stat_ic_notification)            .setContentTitle("FCM Message")            .setContentText(messageBody)            .setautoCancel(true)            .setSound(defaultSoundUri)            .setContentIntent(pendingIntent);    notificationmanager notificationmanager =            (notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);    notificationmanager.notify(0 /* ID of notification */, notificationBuilder.build());}

}

解决方法:

onTokenRefresh()方法在第一次安装应用程序时不会触发.它仅由specific scenarios触发.

要获得令牌,您必须在应用程序的开头调用FirebaseInstanceID.getInstance().getToken()(例如onCreate或其他内容).

总结

以上是内存溢出为你收集整理的没有刷新令牌firebase android全部内容,希望文章能够帮你解决没有刷新令牌firebase android所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1116208.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存