2

私は私のサンプルについて説明し、問題の理解に役立つ最小限のコードを与えました。私のGradleファイルにFirebaseが通知のために働くことができません

、私の依存関係インサイド終わり

apply plugin: 'com.google.gms.google-services' 

{}私は

compile 'com.google.firebase:firebase-messaging:9.2.0' 

を追加している私はまた、依存関係{}

compile 'com.google.android.gms:play-services:9.2.0' 
compile 'com.google.android.gms:play-services-maps:9.2.0' 
compile 'com.google.android.gms:play-services-ads:9.2.0' 
compile 'com.google.android.gms:play-services-auth:9.2.0' 
compile 'com.google.android.gms:play-services-gcm:9.2.0' 
compile 'com.google.android.gms:play-services-analytics:9.2.0' 
compile 'com.google.android.gms:play-services-location:9.2.0' 
compile 'com.google.maps.android:android-maps-utils:0.4.+' 

に次きました私が持っているマニフェスト

 <!-- Google Cloud Messaging --> 
     <uses-permission 
      android:name="com.mcruiseon.buseeta.permission.C2D_MESSAGE" 
      android:protectionLevel="signature"/> 
     <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> 

<service android:name=".support.NotificationIncoming"> 
      <intent-filter> 
       <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
      </intent-filter> 
     </service> 
     <service android:name=".support.NotificationsIDService"> 
      <intent-filter> 
       <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
      </intent-filter> 
     </service> 

NotificationIncoming.javaは私がプロジェクト

  • はSHA1フィンガープリントを追加しました作成し、以下の

    1. を行っているFirebaseで

      public class NotificationIncoming extends FirebaseMessagingService { 
      
      
          @Override 
          public void onMessageReceived(RemoteMessage remoteMessage) { 
      
           Log.d(God.LOG_TAG, "From: " + remoteMessage.getFrom()); 
           Log.d(God.LOG_TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 
           sendNotification(remoteMessage.getNotification().getBody()); 
          } 
      
          private void sendNotification(String messageBody) { 
           Intent intent = new Intent(this, MyBookings.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.drawable.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()); 
          } 
      } 
      
      私NotificationIDServiceで

      public class NotificationsIDService extends FirebaseInstanceIdService { 
          @Override 
          public void onTokenRefresh() { 
      
           String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
           Log.d(God.LOG_TAG, "Refreshed token: " + refreshedToken); 
           sendRegistrationToServer(refreshedToken); 
          } 
          private void sendRegistrationToServer(String token) { 
           // Add custom implementation, as needed. 
          } 
      } 
      

      を持っています

    2. google-services.jsonをダウンロードし、アプリのフォルダにコピーしました。

    SHA1と同じキーストアから署名付きアプリケーションを作成しました。そして、アプリケーションを実行しました。 Firebaseコンソールからメッセージを送りました。

    No luck。私は何が欠けていますか?本当に基本的なものだと思います。これを読んで、すべての人のために

    EDIT

    は、上記の私のために完全に働きました。

  • +0

    は、コンソール上のドロップダウン存在からアプリのパッケージ名を選択し、ところで 'は<使用許可 アンドロイド:名=「com.mcruiseon.buseeta.permission.C2D_MESSAGE」を アンドロイド:のProtectionLevel =「署名」/> 'は不要ですか? –

    +0

    はい、私はそれをしました。なんらかの理由で、一式の通知が遅れて受信されました。 – Siddharth

    答えて

    0

    上記の設定/コードが変更されずに動作するようになり、私はこれらの通知を遅く受け取りました。

    @ shadab-ansari、はい私はドロップダウンからアプリを追加しました。私はマニフェストからパーミッションを削除していません:)、その作業は今、私はそれに触れていません。

    +0

    これはばかばかしいようです。でも、私にとっても同じ問題が起きています。それは今まで働いていましたが、設定やキー、コードを変更することなく、動作を停止しました。非常に奇妙です –

    関連する問題