【问题标题】:Android Studio -error: cannot access InternalTokenProvider // firebaseAuth = FirebaseAuth.getInstance();Android Studio -error: 无法访问 InternalTokenProvider // firebaseAuth = FirebaseAuth.getInstance();
【发布时间】:2020-07-18 05:41:47
【问题描述】:

每当为 Android 推送通知添加云消息传递依赖项时,我都会收到此错误:

error: cannot access InternalTokenProvider
         firebaseAuth = FirebaseAuth.getInstance();
                                    ^   class file for
com.google.firebase.internal.InternalTokenProvider not found

implementation 'com.google.firebase:firebase-messaging:20.2.3'

我的 Firebase 实时数据库在没有这种依赖关系的情况下运行完美。有什么问题,我该如何解决?

【问题讨论】:

  • 请写出更多细节,比如你应该声明这是针对 android 的,而不是指望人们推断出来。
  • edit 并重新格式化您的问题,使其可读。格式化帮助可用here
  • 为什么 puch firebase 消息传递需要身份验证?您想联系已登录的人吗?

标签: android firebase push-notification firebase-cloud-messaging


【解决方案1】:

我自己修复了错误。我更改了 FirebaseAuth、FirbaseDatabase 和 FirebaseStorage 的版本

implementation 'com.google.firebase:firebase-messaging:20.2.3'

implementation 'com.google.firebase:firebase-auth:19.3.2'

implementation 'com.google.firebase:firebase-database:19.3.1'

implementation 'com.google.firebase:firebase-storage:19.1.1'

解决了。

有用的链接:link

【讨论】:

    【解决方案2】:

    没有 FIrebase 身份验证!完美运行。

    public class MyFirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
    int notifyId = 0;
    
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d("Service", "From: " + remoteMessage.getFrom());
    
        if (remoteMessage.getData().size() > 0) {
            Log.d("Service", "Message data payload: " + remoteMessage.getData());
        }
    
        if (remoteMessage.getNotification() != null) {
            Log.d("Service", "Message notification: " + remoteMessage.getNotification().getBody());
        }
        sendNotification(remoteMessage.getData().get("message"));
    }
    
    private void sendNotification(String message) {
        Intent intent = new Intent(this, Splash.class);
        intent.putExtra("isNotify", true);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    
        Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setColor(ContextCompat.getColor(this, R.color.colorAccent))
                .setContentTitle("your app name") //put your app name here
                .setWhen(System.currentTimeMillis())
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(uri)
                .setContentIntent(pendingIntent)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        assert notificationManager != null;
        notificationManager.notify(notifyId, builder.build());
        notifyId++;
    }}
    

    如果你想添加token,之后添加它!

    【讨论】:

    • 为不需要登录的客户推送通知。
    • 然后使用我的代码完美运行!如果您的问题得到解决,也给我投票并标记我的答案正确!
    • 或者你可以试试 firebaseAuth = FirebaseAuth.getInstance().getCurrentUser();
    • 我使用 instagram - wtfrajnish
    • firebaseAuth = FirebaseAuth.getInstance().getCurrentUser() 试试这个
    猜你喜欢
    • 1970-01-01
    • 2023-03-23
    • 2014-07-14
    • 2020-01-05
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多