1

I am developing an android app in Android Studio on Android 5.1 (this is an app for a specific tablet). I need my app to be a device owner and it has to run in kiosk mode. I have already set device owner by: db shell dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr And now I am wondering if there is a way to set my app as device owner programatically without NFC, phone rooting or using Android Studio shell. I have already used in my code: Runtime.getRuntime().exec("adb shell dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr"); but it didn't work. (How to make my app device owner without NFC and ADB shell command)

My second question is: When app is pinned to the screen the navigation bar is still displayed (only with back button, which show Toast). Is it possible to disable the display of this bar?

And my last question: I want my app to start at the start of the device. I added:

<category android:name="android.intent.category.HOME"/>

to my Activity and implemented BroadcastReceiver. The first time my app starts Android asks to choose home application. Is there a way to set the app as home application without user asking?

Best regards

bogóś
  • 51
  • 7

1 Answers1

-1

You have to use DeviceAdminReceiver class in your app for example

class AdminReceiver : DeviceAdminReceiver() {
    companion object {
        private const val TAG = "AdminReceiver"

        fun getComponentName(context: Context): ComponentName =
                 ComponentName(context.applicationContext, AdminReceiver::class.java)
    }

    override fun onEnabled(context: Context?, intent: Intent?) {
         Log.i(TAG, "Enabled")
         showLongToast(context!!, R.string.app_enable)

         MainActivity.launch(context)

         super.onEnabled(context, intent)
    }

     override fun onDisabled(context: Context?, intent: Intent?) {
         Log.i(TAG, "Disabled")
         showLongToast(context!!, R.string.app_enable)
         super.onDisabled(context, intent)
    }
 }

You can see full example in my repository https://github.com/ArtemBotnev/AdminApp/blob/master/app/src/main/java/ru/rs/adminapp/AdminReceiver.kt

Artem Botnev
  • 2,267
  • 1
  • 14
  • 19
  • 1
    Hi, thank You for you response, but it doesn't solve my problem. I run Yours example in Android Studio and Your application is not a Device Owner, it's an admin and it's easy to unpin the screen. I implemented my version of DeviceAdminReceiver, setLockTaskPackages by DevicePolicyManager and set my app as device owner in adb shell. But I want to set my app as Device Owner without adb shell, nfc or rooting. – bogóś Jun 19 '19 at 09:24
  • 1
    @bogóś it's not possible. There are few ways : via adb command and only if it's new device or after factory reset. NFC or QR code. – Peter Oct 28 '19 at 08:09