3

I have an app that runs in the background and starts an activity when a certain event occurs on the phone. I'm finding with Android 5.0 that when the user has screen pinning turned on with another app, the startActivity(intent) call is ignored completely. My app doesn't know that the activity didn't start, so the user then won't have another chance to see the activity until they manually reopen my app.

Is there any sort of event I can register for to be notified when screen pinning is turned off, so I can reattempt to start my activity?

jokeefe
  • 1,836
  • 4
  • 22
  • 27
  • 1
    Rather than starting an activity, you might consider switching to using a full-screen `PendingIntent` on a `Notification`. Pre-5.0, this will start the activity specified in the `PendingIntent`. On 5.0+, it will result in a heads-up `Notification`. I have not played with pinning yet, but I would hope that a heads-up `Notification` still appears, or at least winds up as a regular `Notification`. – CommonsWare Nov 11 '14 at 00:32
  • @CommonsWare I haven't experimented with notifications, but one of the features originally described (back when screen pinning was announced as "task locking") was that notifications from other apps would *not* appear. – Kevin Krumwiede Apr 20 '15 at 02:21

2 Answers2

3

Here is method in ActivityManager class which tells status of current task if locked or not in case of screen pinning:

!mActivityManager.isInLockTaskMode()

For more details check this link: http://developer.android.com/reference/android/app/ActivityManager.html#isInLockTaskMode%28%29

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
1

Your app must be a device administrator (with administration rights granted by user). Once you have done that, you can implement this callback:

AdminReceiver.onLockTaskModeExiting(Context context, Intent intent)

to do something when pinning mode is stopped.

To see how to make your app an Administrator app : you can check one of my previous answer here

Community
  • 1
  • 1
ben75
  • 29,217
  • 10
  • 88
  • 134
  • Thank you! That's exactly what I was looking for. My app is already setup as a Device Admin, actually. I'm not getting an event trigger for this, however. My `AdminReceiver` class has the `BIND_DEVICE_ADMIN` permission and the `DEVICE_ADMIN_ENABLED` intent-filter in the AndroidManifest.xml. I'm catching other events in the its `onReceive()` method (like password changes), but the `android.app.action.LOCK_TASK_EXITING` event isn't triggering. Do you know if there's any other setup required for this? – jokeefe Nov 11 '14 at 23:11
  • 2
    I've written a complete article explaining Screen pinning available at http://florent-dupont.blogspot.fr/2015/02/android-5-screen-pinning.html. Source code is also available so your can use it to help you get notifications on pin/unpin events. – Florent Dupont Feb 09 '15 at 09:12
  • Is that really for device administrator apps, or only for the device owner app? – Kevin Krumwiede Apr 20 '15 at 02:23
  • @KevinKrumwiede kiosk mode i.e locktaskmode is acceptable full potential via admin/owner mode only – Arul Jan 17 '22 at 12:37
  • @Arul AFAIK, lock task mode is only fully accessible to the device owner, *not* other admin apps. Hence my question. Not that the asker probably cares after eight years... – Kevin Krumwiede Jan 17 '22 at 17:04
  • @KevinKrumwiede lol it's good to answer questions even after eight years. Anyway is there anyway pin screen without dpc or owner access. – Arul Jan 18 '22 at 02:13
  • 1
    @Arul Not as far as I know. But I should clarify that the Device Owner can grant permission to other admin apps. Normal admin apps can't grant it to themselves. – Kevin Krumwiede Jan 19 '22 at 19:48
  • @KevinKrumwiede I figured it out, Only option left out is Samsung knox which is only for enterprise application – Arul Feb 11 '22 at 11:10