简体   繁体   中英

Android stop user from closing the app

Is there a way we can build a custom MDM, to force the app to be always open. ie don't let the user close.

I am building a image gallery app to be on display for users. but I dont want them to be able to close my app.

Thanks

some thing like this ?

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);
        }

But then, I also need to know when the app is closed or killed ?

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. (ie Apple Store) you can't quit the app running on these Ipads

I've written a post specifically on Kiosk mode on Android - past just 'task pinning'.

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

  • Create a DeviceAdminReceiver and put it in your manifest
  • Then, run dpm to give yourself device admin access

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

  • Verify you're the device owner in the app, and you're off to the races

There is a fair amount of work to it, however, once you do the boilerplate, you'll end up using this snippet to enable and disable.

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
    }
}

对于这些情况,不要重新发明轮子,而是安装Android 5.0或更新版本并使用其“kiosk模式”又名“任务固定”

As said by @Sarge from 5.0 there's the Kiosk mode available. If you're not running on 5.0 please let me know and 'ill take some times to search onto my old project and give you a pré lollipop Home-made Kiosk mode (no need to flash the tablet or anything, just programming)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM