2016-06-22 41 views
3

我的Firebase雲消息傳遞存在問題: 我使用2個擴展服務FirebaseInstanceIdService和FirebaseMessagingService實施了一個小應用。Firebase雲消息傳遞:無令牌和奇怪的通知行爲

如果我通過 Firebase控制檯啓動應用程序併發送通知,我會在我的設備上收到通知。 一切正常。 如果我再次打開該應用程序,它會掛起併產生一個黑色的 屏幕。那麼Android Studio控制檯上沒有輸出。 我也沒有從Firebase控制檯收到第二條通知。 然後我得到一個對話框:「應用程序沒有反應等」 再次打開應用程序後,它再次正常工作。

我還沒有得到在logcat中的令牌

火力地堡InstanceIdService(?):

public class InstanceIdService extends FirebaseInstanceIdService 
{ 
    private static final String TAG = "InstanceIdService"; 

    @Override 
    public void onTokenRefresh() 
    { 
     String token = FirebaseInstanceId.getInstance().getToken(); 
     Log.e(TAG, "!!!!!!!!!!!!!!!!!! Got token: " + token); 
    } 
} 

FirebaseMessagingService:

public class MyFirebaseMessagingService extends FirebaseMessagingService 
{ 
@Override 
public void onMessageReceived(RemoteMessage remoteMessage) 
{ 
    sendNotification(remoteMessage); 
} 

public void sendNotification(RemoteMessage remoteMessage) 
{ 
    Intent intent = new Intent(this, MainActivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_ONE_SHOT); 

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setContentTitle(remoteMessage.getFrom()) 
      .setContentText(remoteMessage.getNotification().getBody()) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(0, notificationBuilder.build()); 
} 
} 

在Android Studio控制檯的唯一錯誤是 「無法加載模塊描述符類」,但是這是一個已知的bug,即 。

我希望你能幫助我。

最好的問候, 菲利克斯

編輯:錯誤消息從火力地堡控制檯:(?)

Exception java.lang.RuntimeException: Parcel [email protected]: Unmarshalling unknown type code 1936206469 at offset 68 
android.os.Parcel.readValue (Parcel.java:2087) 
android.os.Parcel.readArrayMapInternal (Parcel.java:2321) 
android.os.Bundle.unparcel (Bundle.java:249) 
android.os.Bundle.getString (Bundle.java:1118) 
com.google.firebase.messaging.FirebaseMessagingService.zzT() 
com.google.firebase.messaging.FirebaseMessagingService.zzm() 
com.google.firebase.iid.zzb$2.run() 
java.util.concurrent.ThreadPoolExecutor.runWorker  (ThreadPoolExecutor.java:1112) 
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587) 
java.lang.Thread.run (Thread.java:841) 

回答

3

我還沒有得到在logcat中的令牌

onTokenRefresh()方法在爲您生成新令牌時調用。每次打開應用程序時都不會調用它。 但是你可以使用FirebaseInstanceId.getInstance().getToken();

如果我啓動應用程序,並通過發送火力地堡控制檯的通知令牌,我讓我的設備上的通知。一切正常。如果我再次打開應用程序,它會掛起併產生黑屏。

我遇到了類似的問題,這通常發生在您沒有網絡連接或網速較慢的情況下。尚無解決方案。 :(

+1

非常感謝。我得到了一個令牌。 – Cyberlander

+0

@Cyber​​lander什麼是修復? – mboy

相關問題