如何停止“按住后退按钮"?逃脱“锁定任务模式"在Android 7+上 [英] How to stop "holding the back button" from escaping "Lock Task mode" on Android 7+

查看:103
本文介绍了如何停止“按住后退按钮"?逃脱“锁定任务模式"在Android 7+上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用锁定任务模式",如 https://developer上所述.android.com/work/cosu.html

I'm attempting to use "Lock Task mode", as described on https://developer.android.com/work/cosu.html

我的目标是让单个应用程序以信息亭模式"运行,以使用户无法离开该应用程序.

My goal is to have a single app running in a "kiosk mode", so that the user cannot leave the app.

我正在使用Google Play中来自Google Play的Google"Test DPC"应用程序作为DPC,我通过以下方式将该设备作为拥有者: adb shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver.

I'm using Google's "Test DPC" app from Google Play as the DPC, which I have made the owner of the device via: adb shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver.

将所有琐碎的应用程序(称为 startLockTask())保持在信息亭模式下,效果都很好.(我已将此琐碎的应用程序添加到允许使用锁定任务模式"的应用程序的测试DPC"列表中.)

It all works really well at keeping a trivial app (which calls startLockTask()) in kiosk mode. (I have added this trivial app to Test DPCs list of apps which are allowed to use "Lock Task mode".)

问题是,如果用户按住后退按钮,他们会在显示"App已被固定:此设备上不允许取消固定"的混乱提示时逃脱"Lock Task mode"(锁定任务模式).

The problem is that if a user holds the back button, they escape "Lock Task mode" while displaying a confusing toast of "App is pinned: unpinning is not allowed on this device".

有没有办法停止这种逃逸机制?

Is there a way of stopping this escape mechanism?

更新:问题出现在装有Android 7的华硕P00A上,但不是出现在装有Android 6的Android P00C上.

Update: The problem occurs on an Asus P00A with Android 7, but does not occur on an Android P00C with Android 6.

推荐答案

如果用户单击主页"按钮(这可能会破坏上一个活动),然后单击后退"按钮,则我也会遇到类似的问题

I have a similar issue if the user clicks the home button (that can destroy the previous activity), next back button

一个诀窍是停用后退按钮

A trick is to desactivate the back button

@Override
public void onBackPressed() {
    // do nothing
}

这篇关于如何停止“按住后退按钮"?逃脱“锁定任务模式"在Android 7+上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆