Android Studio-错误:无法访问InternalTokenProvider//firebaseAuth = FirebaseAuth.getInstance(); [英] Android Studio -error: cannot access InternalTokenProvider // firebaseAuth = FirebaseAuth.getInstance();

查看:83
本文介绍了Android Studio-错误:无法访问InternalTokenProvider//firebaseAuth = FirebaseAuth.getInstance();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当为Android推送通知添加Cloud Messaging依赖项时,我都会收到此错误:

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'

我的Firebase实时数据库在没有此依赖项的情况下可以完美运行.有什么问题,我该如何解决?

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

推荐答案

没有FIrebase Auth!完美运行.

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!

这篇关于Android Studio-错误:无法访问InternalTokenProvider//firebaseAuth = FirebaseAuth.getInstance();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆