2016-07-11 12 views
-2

初めてのことではありませんが、アプリケーションがバックグラウンドのときにGCM/FCMがどのように動作するのか不思議です。未公開アプリのFCMメッセージングは​​うまく機能していますか?

私は自分のアプリケーションを変更していますが、アプリケーションがバックグラウンドのときはdataのメッセージを受信しませんが、フォアグラウンドのアプリケーションでは同じメッセージがうまく受信されます。

私はGoogleのプレイから発行され1をインストールした場合、それはすべての場合にうまく機能しています。

私は戻って、公開アプリケーションのプロジェクトを取得し、それを再構築する場合、アプリがバックグラウンドで動作しているとき、FCMメッセージは受信されません。それは悪夢です。

FCMが完全に公開されていないアプリケーションのために働いているのであれば、私は思ったんだけど!?!

私のメッセージが(アドバンスト休憩クライアントからテスト)されています

{ 
    "registration_ids": [ 
    "feWpp3aQ8sQ:A...dclQ1hSttsf", 
    "feDmzDRi-gw:A...O9ur7oXi", 
    "f7dbqek_rPo:APA91bEu...a1rSje0bNmPq8" 
    ], 
    "data": { 
    "id": 19, 
    "title": "Title test", 
    "msg": "Text of the test", 
    "code": 2, 
    "infosUrl": "www.myexample.com", 
    "eventLocation": "Nowhere", 
    "latitude": 47.90022515672, 
    "longitude": 15.0196307059377, 
    "startDate": "2016/05/14 20:00", 
    "endDate": "2016/05/14 22:00", 
    "publishEndDate": "", 
    "image": "" 
    }, 
    "delay_while_idle": false, 
    "priority": "high", 
    "content_available": true 
} 

私のマニフェスト:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.my.example" 
    android:installLocation="auto" 
    android:versionCode="52" 
    android:versionName="@string/app_version"> 

    <application 
     android:allowBackup="true" 
     android:hardwareAccelerated="false" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:logo="@mipmap/ic_launcher"> 

     <activity 
      android:name=".MainActivity" 
      android:configChanges="keyboardHidden|orientation|screenSize" 
      android:label="@string/app_name"> 

      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

      <intent-filter> 
       <action android:name="android.intent.action.SEARCH" /> 
      </intent-filter> 

     </activity> 

     <activity 
      android:name=".PreferencesActivity" 
      android:label="@string/label_preferenceScreen"/> 

     <activity 
      android:name=".FragmentPreferences" 
      android:label="@string/label_preferenceScreen"/> 

     <service android:name=".MyFcmListenerService"> 
      <intent-filter> 
       <action android:name="com.google.firebase.MESSAGING_EVENT" /> 
      </intent-filter> 
     </service> 

     <service 
      android:name=".MyInstanceIDListenerService"> 
      <intent-filter> 
       <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> 
      </intent-filter> 
     </service> 

     <service 
      android:name=".RegistrationIntentService" 
      android:exported="false" /> 

    </application> 

私のGradle:

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:support-v4:24.0.0' 
    compile 'com.android.support:support-annotations:24.0.0' 
    compile 'org.osmdroid:osmdroid-android:[email protected]' 
    compile 'com.google.firebase:firebase-messaging:9.2.0' 
    compile 'com.google.android.gms:play-services-location:9.2.0' 
    compile 'com.google.android.gms:play-services-appindexing:9.2.0' 
    compile 'com.android.support:appcompat-v7:24.0.0' 
} 
apply plugin: 'com.google.gms.google-services' 

とリスナー:

public class MyFcmListenerService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage fcmMessage) { 

     Map data = fcmMessage.getData(); 

     int code = Integer.parseInt((String) data.get("code")); 

     switch (code) { 
      case 1: // Event 
       .... 
       break; 


      default: 
       break; 
     } 
    } 
} 

あなたは、このような奇妙な問題が発生しました?

答えて

0

通知/ message.WhatのFCMサーバを受け取るために/未発表アプリを公開されているかどうかは関係ありませんがsが有効な登録IDである必要があります。 com.google.firebase.MESSAGING_EVENTアクションであなたのMyFcmListenerServiceがmessages.Thatを受信するための責任があることは、あなたのアプリがあなたのアプリは意志もバックグラウンドで動作しているときはいつでも特定のアクションは、このために発生するたび、あなたはあなた/あなたのアプリに通知するために、そのサービスを意図的に登録している意味します通知/メッセージを受け取る。 MyInstanceIDListenerServiceは、あなたのアプリの登録IDを受け取る責任があります。 アプリがフォアグラウンドかバックグラウンドかにかかわらず、GCM/FCMでメッセージを受信する際に問題はありません。

+0

メッセージが正常にデバイスに送信されました。私は、以前に実行していたプロジェクト(Google Playのアプリを実行中)であっても、プロジェクトが再構築されると、バックグラウンド受信はもう機能しなくなることに気付きました...これは私が今理解できないものです。それは特定のデバイスに固有のものではありません。 – 2ndGAB

関連する問題