2

Ich versuche Firebase Benachrichtigung an ein einziges Gerät zu senden und dass ich die FCM registration token mit dem Code unten Introduction:App abstürzt, wenn Benachrichtigung an ein einziges Gerät zu senden versuchen, von Feuerbasis

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { 

    private static final String TAG = "MyFirebaseIIDService"; 

    /** 
    * Called if InstanceID token is updated. This may occur if the security of 
    * the previous token had been compromised. Note that this is called when the InstanceID token 
    * is initially generated so this is where you would retrieve the token. 
    */ 
    // [START refresh_token] 
    @Override 
    public void onTokenRefresh() { 
     // Get updated InstanceID token. 
     String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
     Log.d(TAG, "Refreshed token: " + refreshedToken); 

     // TODO: Implement this method to send any registration to your app's servers. 
     sendRegistrationToServer(refreshedToken); 
    } 
    // [END refresh_token] 

    /** 
    * Persist token to third-party servers. 
    * 
    * Modify this method to associate the user's FCM InstanceID token with any server-side account 
    * maintained by your application. 
    * 
    * @param token The new token. 
    */ 
    private void sendRegistrationToServer(String token) { 
     // Add custom implementation, as needed. 
    } 
} 

Hier MyFirebaseMessagingService.java Datei Code:

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    private static final String TAG = "MyFirebaseMsgService"; 

    /** 
    * Called when message is received. 
    * 
    * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. 
    */ 
    // [START receive_message] 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     // TODO(developer): Handle FCM messages here. 
     // If the application is in the foreground handle both data and notification messages here. 
     // 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. 
     Log.d(TAG, "From: " + remoteMessage.getFrom()); 
     Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 

     sendNotification(remoteMessage.getNotification().getBody()); 
    } 
    // [END receive_message] 

    /** 
    * Create and show a simple notification containing the received FCM message. 
    * 
    * @param messageBody FCM message body received. 
    */ 
    public void sendNotification(String messageBody) { 
     Intent intent = new Intent(this, SettingsActivity.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.mipmap.ic_launcher) 
       .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()); 
    } 
} 

das Problem ist, dass, wenn ich versuche, Firebase Benachrichtigung zu senden, während die App noch auf dem Bildschirm ist, wird es mehrere Male gibt diesen Fehler Absturz: java.lang.IllegalArgumentException: URI: content://com.android.contacts/phone_lookup/?encrypt=%20%3C%202, calling user: com.android.mms:10015, calling package:com.android.mms

Ich weiß wirklich nicht, was hier falsch läuft!

Bitte lassen Sie es mich wissen.

+2

Können Sie die gesamte Stack-Trace hinzufügen? Ich würde gerne sehen, woher das kommt. –

Antwort

2

Versuchen Debuggen onMessageReceived() müssen Sie immer remoteMessage.getNotification() = null, wenn Sie keine Benachrichtigung Block in Ihre Push senden:

@Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     Log.d(TAG, "From: " + remoteMessage.getFrom()); 
     // Check if remoteMessage.getNotification() == null ?? 
     Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 

     sendNotification(remoteMessage.getNotification().getBody()); 
    } 

Auch Ihre Frage mit voller Fehlerprotokoll aktualisieren.

0

Stellen Sie nur sicher, dass die Zeile "apply plugin: 'com.google.gms.google-services'" in der Datei build.gradle Ihrer App ganz unten in der Datei build.gradle liegt. Andernfalls stürzt die App möglicherweise ab, wenn eine Nachricht empfangen wird.

Verwandte Themen