简体   繁体   中英

Start activity from service android 10

I am trying to create a locker application to show pin view when the user enters to defended application. I created a service that runs and tracks the current foreground application. However, on devices with android version 10 activity is not starting from my service. I know that from android 10 there are restrictions to start an activity from the background, however, there are exceptions either. The activity can start from the background when the application is in the foreground, but it won't help in my case. So the question is how can I start the activity from service to show pin view?

Ps: I tried it with window manager but again in higher android versions there is an annoying notification that can open settings do dismiss overlay permission. Also, I saw a working "app locker" application in the play store, so I believe there is a way.

From android 10 foreground service will work only if u start the service while the app is in foreground. If your app is in background you will need background location permission which has to be requested separate after you gain permission for coarse and fine location. Also if your app is in testing mode and not in Play Store and u update your device to android 10 a fresh install of the app is needed. There is no point in using a foreground service if u want to start that service from background. Just get background location and stop using foreground service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM