Reputation: 67
I have a problem with FCM functionality. When the phone is awake everything is working (notifications are received when the app is in foreground, background or even if the app is dead).
The problem starts when the phone is entering deep sleep.
As I remember wakelocks are not mandatory with FCM.
I'm pushing "data" type notification with "priority":"high" which should wake up the device.
Problem is that notifications will be received when the phone will awake.
public class FCMCallbackService extends FirebaseMessagingService {
private static final String TAG = "FCMCallbackService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent i = new Intent(this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
}
public class FCMInitializationService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
...
}
}
In manifest:
<service android:name="gcmpush.FCMInitializationService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="gcmpush.FCMCallbackService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
How can I wake application using push if the phone is sleeping? What is missing?
BDW - if I'm connected to WiFi and phone will go to sleep, but the application is not working - will it use WiFi to receive push? FCM can start the dead application. But if the app is dead, WiFi lock is not acquired. Can in such case device communicate with FCM Server?
Upvotes: 4
Views: 5465
Reputation: 21551
The following message will not call your onMessageReceived() when your app is in the background or killed, and you can't customize your notification.
{
"to": "/topics/journal",
"notification": {
"title" : "title",
"text": "data!",
"icon": "ic_notification"
}
}
but instead using this will work
{
"to": "/topics/dev_journal",
"data": {
"text":"text",
"title":"",
"line1":"Journal",
"line2":"some data"
}
}
See ref link here
Upvotes: 1