bogóś
bogóś

Reputation: 51

How to set an android app as the device owner

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

Upvotes: 1

Views: 2740

Answers (1)

Artem Botnev
Artem Botnev

Reputation: 2427

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

Upvotes: -1

Related Questions