Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - New apps on Google Play must target Android 8 (API level 26) - PUSH notification in background

From August 2018, all new apps on Google Play must target Android 8 (API level 26) or higher, and from November 2018, all app updates on Google Play must of the same apps on Google Play.

Right now the only way you have to upload a new App that target Android 8 is to edit the file AndroidManifest.template.xml and replace targetSdkVersion = "% targetSdkVersion%" by: Android: targetSdkVersion = "26"

The problem is that from that moment the app has the restrictions introduced by Android O. The permissions considered as dangerous (camera, location, SMS, ...) will not be granted to the app by the mere fact of including them in the AndroidManifest file. Goodbye to the camera, to the GPS, ...

In this web, you can following a few simple steps to start requesting permissions from the user: http://delphiworlds.com/2018/05/targeting-android-8-and-higher/

HOWEVER, target Android 8 has many more implications. My application, for the mere fact of changing the targetSDKVersion from 25 to 26 DOES NOT RECEIVE PUSH NOTIFICATIONS when the application is not running (or in background).

My test is simple: I change the targetSDK and it does not work anymore. I rewind and it works again, both with the app running and with the app in background or closed.

The key is the change of TARGETSDKVERSION because I have always tried selecting the SDK 24.3.3 in the SDK Manager.

I think one of the main reasons is the disappearance of the Background Services in Android O, as they explain in https://blog.klinkerapps.com/android-o-background-services/ But I’m not sure.

MY BIG PROBLEM.

I just uploaded an Android 7 (Level 25) app to Google Play. The problem is that as of November 2018 I will NOT be able to upload updates if I do not change TARGETSDKVERSION to Level 26. But if I do ... I will stop receiving PUSH notifications, and without PUSH notifications, my App DOES NOT WORK FOR ANYTHING.

I confess that I'm a little scared with this

I'm sorry for my English.

Thank you VERY much.

like image 474
Juan M Avatar asked May 27 '18 07:05

Juan M


1 Answers

You will have to make sure that your notification is a high priority, FCM will post it immediately

FCM attempts to deliver high priority messages immediately, allowing the FCM service to wake a sleeping device when necessary and to run some limited processing (including very limited network access). High priority messages generally should result in user interaction with your app. If FCM detects a pattern in which they don't, your messages may be de-prioritized

If your users interact with the notifcaiton FCM will not delay it. Background services may not be allowed in some cases in Android O but it doesn't mean you cannot send notifications

Also your notification will not be displayed if your not using notification channels, You can use this code to create notification channels

public void initChannels(Context context) {
if (Build.VERSION.SDK_INT < 26) {
    return;
}
NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel("default",
                                                      "Channel name",
                                                      NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("Channel description");
notificationManager.createNotificationChannel(channel);

}

like image 168
Suhaib Roomy Avatar answered Sep 20 '22 17:09

Suhaib Roomy