java – Android阻止用户关闭应用程序
作者:互联网
有没有办法我们可以构建自定义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并将其放入清单中
>然后,运行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,android-intent,performance,mdm 来源: https://codeday.me/bug/20190706/1399367.html