Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法实例化receiver com.google.firebase.iid.firebaseInstanceReceiver:java.lang.ClassNotFoundException:_Java_Android_Firebase_Firebase Console_Android Push Notification - Fatal编程技术网

无法实例化receiver com.google.firebase.iid.firebaseInstanceReceiver:java.lang.ClassNotFoundException:

无法实例化receiver com.google.firebase.iid.firebaseInstanceReceiver:java.lang.ClassNotFoundException:,java,android,firebase,firebase-console,android-push-notification,Java,Android,Firebase,Firebase Console,Android Push Notification,我检查了很多答案,但都不起作用。我只想创建一个简单的推送通知应用程序。首先,当我创建一个apk并试图在多个设备上发送它开始崩溃的通知时,我为单个设备创建了一个apk public class MyFirebaseMessagingService extends FirebaseMessagingService { String TAG ="MALIK"; @Override public void onMessageReceived(RemoteMessage rem

我检查了很多答案,但都不起作用。我只想创建一个简单的推送通知应用程序。首先,当我创建一个apk并试图在多个设备上发送它开始崩溃的通知时,我为单个设备创建了一个apk

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    String TAG ="MALIK";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // ...
        sendNotification(remoteMessage.getNotification().getBody());
        // TODO(developer): Handle FCM messages here.
        Log.d(TAG, "From: " + remoteMessage.getFrom());

        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());

            if (/* Check if data needs to be processed by long-running job */ true) {
                // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.

            } else {
                // Handle message within 10 seconds

            }

        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
            sendNotification(remoteMessage.getNotification().getBody());
        }

        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated. See sendNotification method below.
    }

    @Override
    public void onNewToken(String token) {

        Log.d(TAG, "Refreshed token: " + token);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.

    }

    private void sendNotification(String messageBody) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String channelId = getString(R.string.default_notification_channel_id);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.ic_launcher_background)
                        .setContentTitle(getString(R.string.fcm_message))
                        .setContentText(messageBody)
                        .setAutoCancel(true)
                        .setSound(defaultSoundUri)
                        .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",
                    NotificationManager.IMPORTANCE_DEFAULT);
            notificationManager.createNotificationChannel(channel);
        }

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    }
}

该错误可以总结为ClassNotFoundException

这意味着称为类的代码不在类路径中。 问题可能是因为:

需要添加库Firebase iid

添加了库firebase messaging,也添加了此类,但它非常旧或非常新,因此与您的代码不兼容

确保将firebase消息添加到项目中: 如果您的代码是从古代博文中复制的,请添加较低版本的firebase消息传递库。否则,如果您的代码是新的,而firebase消息是旧的,请尝试升级库版本。
有关的详细信息。

可以将错误总结为ClassNotFoundException

这意味着称为类的代码不在类路径中。 问题可能是因为:

需要添加库Firebase iid

添加了库firebase messaging,也添加了此类,但它非常旧或非常新,因此与您的代码不兼容

确保将firebase消息添加到项目中: 如果您的代码是从古代博文中复制的,请添加较低版本的firebase消息传递库。否则,如果您的代码是新的,而firebase消息是旧的,请尝试升级库版本。
有关的更多信息。

非常感谢。现在它在银行里起了很大的作用。现在它正在工作
// use compile instead of implementation if it's unknown
implementation "com.google.firebase:firebase-iid:+" // 18.0.0 or 20.0.0
// use compile instead of implementation if it's unknown
implementation "com.google.firebase:firebase-messaging:+" // 18.0.0 or 20.0.0