22

i'm developing lockscreen application, and i want to disable home button,

my app is - Device Owner and Device Administrator

now i'm usnig screen pinning for disable home button.

but if i started activity each time i get msg "Screen pinned" and on close "Screen Unpinned" and if click on home then, "Unpinning isn't allowed by your organisation"

I want to remove all those toast messages.

gotqn
  • 42,737
  • 46
  • 157
  • 243
Sangha_development
  • 253
  • 1
  • 4
  • 9

2 Answers2

12

Assuming you used the ADB to list your app as a Device Owner, you can use a similar command prompt to disable all toast messages:

adb shell appops set android TOAST_WINDOW deny

For this command to work, cd to the directory where your adb.exe resides (except if you added it to the PATH). This will disable all toast messages to the android device that is connected (virtual or not). If there are multiple devices, the first one found will be selected.

Jenever
  • 500
  • 5
  • 17
  • 3
    That does not answer the question, Sangha_development just want disable a few Toast, not all. – Alexandre Gombert Dec 13 '17 at 13:04
  • I guess that's why my answer wasn't accepted then. Still, it could be used as a workaround. If you want to show other messages to the user, you can mimic toast-like behavior using a custom dialog that dismisses automatically after a few seconds. It's not that difficult... – Jenever Dec 13 '17 at 15:06
  • 1
    This might depend on the Android device, but this doesn't disable all toasts the device will show. I have a Device Owner application that can still show toast messages, but other system toasts (Such as the screen pinning ones) are not shown. – Tyler Hietanen Jan 24 '20 at 19:08
  • 1
    Perfect, works for me, system toast including screen pinning toast are disabled but my application(which is a device owner) toast are visible as I've wanted. – FutureJJ Mar 26 '20 at 06:36
  • appops set TOAST_WINDOW deny; @AlexandreGombert You can do like this to disable specify application's toast only – linjiejun Mar 03 '22 at 06:50
  • PLEASE MARK AS ACCEPTED ANSWER! @Jenever deserves it. This also worked for me and solved the problem as specified, ie. disable system toasts and keep toasts from the application, and worked with just this one line, `adb shell appops.. `. This was a MAJOR issue for me, as my kiosk mode app is for "dumb" users who would be baffled by "screen pinned", "screen unpinned, "To unpin this screen, touch and hold the Back and ...", etc. It was so irritating that I almost abandoned Kiosk mode. Maybe the "solution" is device dependent, unfortunately, but it certainly works for some devices. For me, LG K9. – Stephen Hosking Aug 06 '22 at 22:45
5

There seems to be no override or "whitelist" or policy that allows even a device owner to override this message.

Here's the code that shows the toast: http://androidxref.com/6.0.1_r10/xref/frameworks/base/services/core/java/com/android/server/am/LockTaskNotify.java#74.

Here's the code that calls this show method when a locked task is shown: http://androidxref.com/6.0.1_r10/xref/frameworks/base/services/core/java/com/android/server/am/ActivityStackSupervisor.java#3919.

There are no flags or resources that can be overridden here as far as I have found. If you have access to source, you will need to comment out the line that invokes show.

scorpiodawg
  • 5,612
  • 3
  • 42
  • 62
  • Maybe we can never allow app to back to first locked activity? Forcing second activity with in 'onResume' ? http://androidxref.com/6.0.1_r10/xref/frameworks/base/services/core/java/com/android/server/am/ActivityStackSupervisor.java#3912 – Magillus Jan 08 '18 at 14:16