Closed PulsarFX closed 2 years ago
What intent are you using, which action?
If it's one of these from the list I could try it myself, probably with some automation tool or in an emulator. https://gpslogger.app/#howtoautomategpslogger I won't be surprised if there is some lockscreen related restrictions, I recently saw that, on recent versions of Android, the 'start on boot' feature doesn't work until the lock screen is unlocked.
This is the intent I use to start:
Intent i = new Intent("com.mendhak.gpslogger.TASKER_COMMAND");
i.SetPackage("com.mendhak.gpslogger");
i.PutExtra("immediatestart", true);
I had the autostart issue on my own app, too (Android 11). I had to request Draw Over Other Apps to make it work again.
I can't write a custom app to recreate the exact scenario but the closest I tried now was a similar thing with Llama Automate app. I set it so when the USB charging was unplugged, it sent the broadcast to GPSLogger. My testing shows it working even with screen off. I have Android 13. Could you try it as well to compare.
Is your app itself restricted? eg if you do some logging it could show whether or not it send the broadcast. If you have an APK I could try running it in an emulator? I see the emulator has controls to show a change of charging status, if that's the event that causes the app to send the broadcast.
I think, using some automation tool is good enough for this test.
Whops, I was wrong. I dropped the dedicated intent in favor of a generic "get launch intent" loop:
Intent intent = pm.GetLaunchIntentForPackage(packageName);
Application.Context.StartActivity(intent);
This results in the following intent:
act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.mendhak.gpslogger cmp=com.mendhak.gpslogger/.GpsMainActivity
(where flg=0x10000000 == NewTask)
which succeeds with screen on, but nothing happens with screen off.
After adapting the code to call intent com.mendhak.gpslogger.TASKER_COMMAND
GpsLogger starts with and without the screen on.
(Tested in Android 9 Emulator)
My Xamarin App won't start with the Android 11 emulator for some reason, so I'll close this for now.
Thanks for your effort!
Ok, the real device thinks otherwise. Sometimes it will launch GpsLogger but most of the time not. Got to do more investigation on that. First I thought it was because of a locked screen, but that's not the case
This might be an issue?
10-10 22:44:36.024 bq Aquaris X Info 10706 pulsarfx.chargemon.AppStarter broadcast gpslogger start
10-10 22:44:36.052 bq Aquaris X Warning 1755 ActivityManager Foreground service started from background can not have location/camera/microphone access: service com.mendhak.gpslogger/.GpsLoggingService
but it did start gpslogger and itself started logging. I added another notify right before launching the app, which seemed to have helped. (surrounded by wake locks as before)
Will close for now. I think it might also be a problem with deep sleep.
After a long sleep GPSlogger was not started, but another app still did.
edit: it event won't start when triggered by hand from my app. I am confused.
I've an app which starts several other apps when the phone is moved or receives power from the car. For GpsLogger I use the INTENT to do so, which worked fine so far. After upgrading my device to Android 11 / LineageOs 18.1 this doesn't work anymore when the screen is off. Torque or other apps work as before. It makes no difference if the device was already unlocked or not. Do you have any advice on this? Or is it a bug? I am confused.