gpt4 book ai didi

java - Android 阻止用户关闭应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:03 25 4
gpt4 key购买 nike

有没有一种方法可以构建自定义 MDM,以强制应用程序始终打开。即不要让用户关闭。

我正在构建一个要向用户展示的图片库应用程序。但我不希望他们能够关闭我的应用程序。

谢谢

像这样的东西?

public class IntentReceiver extends BroadcastReceiver {
public static final String TAG = IntentReceiver.class.getSimpleName();


@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive - intent => " + intent.getAction());

//Get Intent
String action = intent.getAction();

if("android.intent.category.HOME".equals(action)) {

Intent i = new Intent();
i.setClass(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}

但是,我还需要知道应用何时关闭或终止?

Let me try to explain better. imagine if an artist wants to display his work via 10 android device. all in the Wall. So he can use this app. I want to lock-down the device. to only run this app and nothing else to work. Similar conset when you go to a phone shop and all the device is running a demo app and you can't quit it with out a password. (i.e Apple Store) you can't quit the app running on these Ipads

最佳答案

我专门写了一篇关于 Android 上的 Kiosk 模式的文章——过去只是“任务固定”。

http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root/

  • 创建一个 DeviceAdminReceiver 并将其放在您的 list 中
  • 然后,运行 dpm 为您自己授予设备管理员访问权限

adb shell dpm set-device-owner com.sureshjoshi.android.kioskexample/.AdminReceiver

  • 在应用中验证您是设备所有者,然后您就可以开始比赛了

这需要大量工作,但是,一旦您完成了样板文件,您最终将使用此代码段来启用和禁用。

private void enableKioskMode(boolean enabled) {
try {
if (enabled) {
if (mDpm.isLockTaskPermitted(this.getPackageName())) {
startLockTask();
mIsKioskEnabled = true;
mButton.setText(getString(R.string.exit_kiosk_mode));
} else {
Toast.makeText(this, getString(R.string.kiosk_not_permitted), Toast.LENGTH_SHORT).show();
}
} else {
stopLockTask();
mIsKioskEnabled = false;
mButton.setText(getString(R.string.enter_kiosk_mode));
}
} catch (Exception e) {
// TODO: Log and handle appropriately
}
}

关于java - Android 阻止用户关闭应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31913909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com