How To Start An Activity From Background in Android 10?

前端 未结 4 1107
暗喜
暗喜 2020-12-31 01:22

I am building an android app where I need to start an activity from background. I am using a ForegroundStarter which extends Service for accomplishing this. I have an activi

相关标签:
4条回答
  • 2020-12-31 01:29

    I do not have enough reputation to comment solution https://stackoverflow.com/a/59067224/8995217 so I try to leave my answer on it for MIUI rom

    It seems need to grand some permissions for app running on Xiaomi phones. Go to phone settings -> Apps -> Manage apps then find your app.

    On app info page go to other permissions and enable the following options

    • Show on Lock screen
    • Display pop-up windows while running in the background
    • Permanent notification

    It works for Xiaomi Redmi Note 8T

    0 讨论(0)
  • 2020-12-31 01:32

    Not sure if it's right to do it this way, but I did not have enough time (app is only for company internal use).

    I used permissions:

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    

    and then every user has to go to setting -> permissions of the app and then check box in advanced settings for function "show the app over others"

    Sorry for my English or not exactly the right solution, but it worked, so good hotfix for me.

    On Pixel 4 it will be looking like this:

    0 讨论(0)
  • 2020-12-31 01:41

    You should include to AndroidManifest.xml below permission.

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    
    0 讨论(0)
  • 2020-12-31 01:51

    As you mentioned Restrictions on starting activities from the background

    It is stated that

    Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background.

    They also mentioned in their note is that.

    Note: For the purposes of starting activities, an app running a foreground service is still considered to be "in the background"

    This means if you're using a foreground service to start an Activity it still considers the App is in the background and won't launch an app Activity.

    Solution: Firstly, You can't start the app if it is running in the background from Android 10 (API level 29) and higher. They have provided a new way to overcome this behavior which is that instead of calling app you can show a high-priority notification with a full-screen intent.

    Full-Screen Intent behaves such as if your device screen is Off It will launch your app Activity which you desired. but if your app is in background and screen is on then it will just show a notification. If you click on the notification then it will open your app.

    For more information on High-Priority Notification and Full-Screen Intent you can check it here Display time-sensitive notifications

    0 讨论(0)
提交回复
热议问题