OneSignal with targetSdkVersion=26 getting error Background start not allowed: service Intent { cmp=***/com.onesignal.GcmIntentService(has extras) }

Hi, I’ve updated plugin and now i’m having crash on Android when application go into suspended state.That’s my call stack: 
 

 I/Corona:  core 142:    suspended    E/AndroidRuntime: FATAL EXCEPTION: FocusHandlerThread Process: com.adb.android.app.myapp, PID: 23761 java.lang.IllegalArgumentException: No such service ComponentInfo{com.adb.android.app.myapp/com.onesignal.SyncJobService} at android.os.Parcel.readException(Parcel.java:1947) at android.os.Parcel.readException(Parcel.java:1889) at android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:180) at android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:44) at com.onesignal.OneSignalSyncServiceUtils.scheduleSyncServiceAsJob(OneSignalSyncServiceUtils.java:137) at com.onesignal.OneSignalSyncServiceUtils.scheduleSyncTask(OneSignalSyncServiceUtils.java:113) at com.onesignal.OneSignalSyncServiceUtils.scheduleSyncTask(OneSignalSyncServiceUtils.java:60) at com.onesignal.OneSignal.onAppLostFocus(OneSignal.java:1089) at com.onesignal.ActivityLifecycleHandler$AppFocusRunnable.run(ActivityLifecycleHandler.java:171) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:171) at android.os.HandlerThread.run(HandlerThread.java:65)

first recognizable call is from OneSignal.onAppLostFocus() method, do you have any ideas how to deal with it?

Bug happens when i stay 2 seconds or longer on native.showPopup from code below, but when i close alert fast enough then bug dosn’t appear. Any ideas? 

local permissionOptions = { appPermission = "android.permission.READ\_PHONE\_STATE", urgency = "Critical", listener = function(e) end, rationaleTitle = "Lorem ipsum", rationaleDescription = "Lorem ipsum", settingsRedirectTitle = "Lorem ipsum", settingsRedirectDescription = "Lorem ipsum" } native.showPopup( "requestAppPermission", permissionOptions )

I’ve also updated Corona from 3.178 to 3.408.

Fixed! I’ve realized that bug was only on android 8+, so i changed my target sdkVersion to 28 and changed dependencies in gradle file to look for version 28.0.0. And bug is gone.

dependencies {

   …
   implementation ‘com.android.support:support-annotations: 28.0.0

}

@josh_OneSignal @naveen_pcs @zdmitrynsk 

Just in case, “com.ansca.corona.SystemStartupBroadcastReceiver” is explained in the AndroidManifest.xml file in all of the sample projects for Corona Native users.

\<!-- Receiver which automatically starts this application after the Android device starts up. This is needed to show this application's active status bar notifications and reschedule pending notifications after the device boots up, because they will only be shown if the app is running. This receiver only works if the "android.permission.RECEIVE\_BOOT\_COMPLETED" permission has been set. --\>

What that broadcast receiver does is start up a Corona app in the background when the Android device finishes booting up. This should be used by apps that support local/push notifications because the app’s notifications will only be shown on the Android status bar if the app is running in the background. That is, if you force quit the app, then all of its notifications in the status bar will disappear. This is standard Android behavior. Starting up an app in the background on boot-up is normal for apps that display notifications, such as the standard Gmail app.
 

Now, a Corona app will not be started in the background on boot-up by default. You have to opt into it by adding Android permission “android.permission.RECEIVE_BOOT_COMPLETED” to your AndroidManifest.xml file… or to your “build.settings” if you are a Corona Simulator user. Otherwise, this broadcast receiver will be ignored by the Android OS.

Can’t say anything about an error right now though, looks like some manufacturers (Samsung specifically) changed notification logic in Android 8 or something, we’ll look into it asap. Can’t reproduce an issue straight away, but stay tuned!

Any updates on this?

Actually, yes!

We’ve found inconsistencies in the new Android notification system. Our engineers are working on the solution, but I can’t give you an ETA for now, stay tuned!

Awesome, great to hear!!

Any updates in the last couple weeks?

No news dor now, we are still looking into it.

I’ve got some more errors with applications built by Corona Native that contains OneSignal plugin on Android 8. 

Bug occurred when i minimalized the application to background (by pressing home button on device)

To solve this i compared Manifest from Corona Native build and Manifest generated by Corona Simulator build (from the same code) and i noticed that some tags were only present in manifest generated from CoronaSimulator build: 
 

\<service android:name="com.onesignal.NotificationRestoreService"/\> \<service android:name="com.onesignal.GcmIntentJobService" android:permission="android.permission.BIND\_JOB\_SERVICE"/\> \<service android:name="com.onesignal.RestoreJobService" android:permission="android.permission.BIND\_JOB\_SERVICE"/\> \<service android:name="com.onesignal.RestoreKickoffJobService" android:permission="android.permission.BIND\_JOB\_SERVICE"/\> \<service android:name="com.onesignal.SyncJobService" android:permission="android.permission.BIND\_JOB\_SERVICE"/\>

When i added them to my manifest i could finally minimalize my app without errors. 

BTW documentation about setup OneSignal plugin on https://documentation.onesignal.com/docs/corona-sdk-setup  is slightly deprecated. I suggest you to update them.

For example: there is still note about adding plugins from DailyBuilds server or about adding deprecated google-play-services_lib. 

@p.kanarek The AndroidManifest.xml entries should be getting added automatically to the finial AndroidManifest.xml built into your APK.

What errors were you getting without these entries when you backgrounded your app? Attach the full stack trace from the logcat if you can

Thanks.

Hi, Any news from corona? I would like to release update for my app but don’t want to have problems as app relays mainly on notifications.

I’m investigating.

Any update?

hi, any update?

We are focused on rebuilding the Android build system which is required by Google. Hopefully, these issues can fall into place after that. This is a big project.

If you are pressed for time, perhaps you should use OneSignal’s REST api. Many people have used it successfully.

Rob

Thanks for the update… I think using REST api will not help as OneSignal Josh notices that this error comes from Corona notification plugin, so does not matter if it’s a rest or onesignal plugin.

If you will be able to fix it earlier it would be great as I am blocked for the past few months.

We moved to build 3462 and the problem went away. See https://forums.coronalabs.com/topic/74223-illegalstateexception-crashes/