我有以下表現 -GcmListenerService onMessageReceived稱爲只有當應用程序在前臺
<service
android:name=".RegistrationIntentService"
android:exported="false" />
<service
android:name=".TestGcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.test" />
</intent-filter>
</service>
<service
android:name=".RegistrationIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.test" />
</intent-filter>
</receiver>
而繼onMessageReceived
方法 -
@Override
public void onMessageReceived(String from, Bundle data) {
ObjectMapper objectMapper = new ObjectMapper();
Message message;
try {
message = objectMapper.readValue(String.valueOf(data.get("message")), Message.class);
MessageNotification.notify(this, message, 1);
} catch (IOException e) {
e.printStackTrace();
}
}
會發生什麼事是,onMessageReceived
被稱爲只有當應用程序在前臺。否則它不會被調用,並且不會顯示通知。當我打開應用程序時,所有通知都會一次顯示。
不是GcmListenereService
如果鎖定並喚醒設備工作?如何解決這個問題?