Is it possible to make my application work in safe mode?

48,705

Solution 1

I know this question is old, but perhaps this will help someone. If your application is Device Owner or Profile Owner on the primary user, you can disable safe mode completely (it works without root):

DevicePolicyManager manager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName admin = new ComponentName(getApplicationContext(), DeviceAdminReceiver.class);
// To disable safe boot
manager.addUserRestriction(admin, UserManager.DISALLOW_SAFE_BOOT);
// To enable safe boot again
// manager.clearUserRestriction(admin, UserManager.DISALLOW_SAFE_BOOT);

EDIT: You can set Device Owner or Profile Owner simply via ADB: https://developer.android.com/studio/command-line/adb#dpm

adb shell dpm set-device-owner com.example.deviceownerapp/.DeviceAdminReceiver

Note that you must have no accounts added when activating device owner (you don't have to do system reset though, just remove all account from settings). After device owner is set, you can add any accounts again.

Solution 2

If you create a shortcut of that particular app that you want to launch in safe mode, you can do so while in safe mode. But you should be in normal mode when creating the shortcut.

Solution 3

The only way to do this is to make the user app a system app on /system/app

But if your device is rooted there is an easy way to do this

  1. download lucky patcher and enable root access

  2. use the search option to find the app you want to be able to use in safe mode or just find it in the scrolling menu

  3. click on the app, click on tools, then press move to /system/app

  4. after the process is complete the device will have to be restarted

  5. the user app is now able to be accessed in safe mode

Share:
48,705
Devu Soman
Author by

Devu Soman

Updated on July 09, 2022

Comments

  • Devu Soman
    Devu Soman almost 2 years

    I have an android application which lists installed and system applications separately. When the user tries to reboot the device from my application it will open my application instead of default home launcher.

    But when the device is rebooted to 'safe mode' all logic crashes .ie, the device rebooted to my application in safe mode but it does not list any installed applications and stops its working.

    1. Is it possible to make my application work in 'Safe mode' also?

    2. Is there any way to prevent the device from going to 'safe mode' while running my application like using a RECEIVE_BOOT_COMPLETED broadcastreceiver?

    3. What is device admin applications? Is it helpfull in this situation?

    4. Is it possible to detect safe mode programmatically?

    Thanks in advance

  • Andrea Thacker
    Andrea Thacker over 8 years
    Has anyone verified this answer?
  • PC.
    PC. almost 8 years
    It does not work. A Toast is shown which says - Download app disabled in Safe mode
  • Tyler
    Tyler over 5 years
    Thanks that helped me. Here is an explanation about how to become a Device Owner or Profile Owner: developers.google.com/android/work/play/emm-api/prov-devices
  • Robyer
    Robyer over 5 years
    I updated answer with explanation how to enable Device Owner simply via ADB.