Android Studio -error: cannot access InternalTokenProvider // firebaseAuth = FirebaseAuth.getInstance();

坚强是说给别人听的谎言 提交于 2020-07-23 06:45:58

问题


I get this error whenever adding Cloud Messaging dependencies for Android push notifications:

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'

My Firebase Realtime Database working perfect without this dependencies. What is the problem, and how can I fix it?


回答1:


Without FIrebase Auth! Running perfectly.

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++;
}}

If you want to add token add it afterwards!




回答2:


i fixed the errror my self. I have changed Versions of FirebaseAuth, FirbaseDatabase and 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'

got solved.

Useful link: link



来源:https://stackoverflow.com/questions/62965094/android-studio-error-cannot-access-internaltokenprovider-firebaseauth-fir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!