初めてのことではありませんが、アプリケーションがバックグラウンドのときに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;
}
}
}
あなたは、このような奇妙な問題が発生しました?
メッセージが正常にデバイスに送信されました。私は、以前に実行していたプロジェクト(Google Playのアプリを実行中)であっても、プロジェクトが再構築されると、バックグラウンド受信はもう機能しなくなることに気付きました...これは私が今理解できないものです。それは特定のデバイスに固有のものではありません。 – 2ndGAB