简体   繁体   English

如何将安卓应用设置为设备所有者

[英]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).我正在 Android 5.1 上的 Android Studio 中开发一个 android 应用程序(这是一个针对特定平板电脑的应用程序)。 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.我已经通过以下方式设置了设备所有者:db shell dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr 现在我想知道是否有办法以编程方式将我的应用程序设置为设备所有者而无需 NFC、手机生根或使用 Android工作室外壳。 I have already used in my code: Runtime.getRuntime().exec("adb shell dpm set-device-owner com.foo.deviceowner/.DeviceAdminRcvr");我已经在我的代码中使用了: 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 ) 如何在没有 NFC 和 ADB shell 命令的情况下让我的应用程序设备所有者

My second question is: When app is pinned to the screen the navigation bar is still displayed (only with back button, which show Toast).我的第二个问题是:当应用程序固定在屏幕上时,导航栏仍然显示(只有后退按钮,显示 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.到我的 Activity 并实现了 BroadcastReceiver。 The first time my app starts Android asks to choose home application.我的应用程序第一次启动 Android 要求选择家庭应用程序。 Is there a way to set the app as home application without user asking?有没有办法在没有用户询问的情况下将应用程序设置为家庭应用程序?

Best regards此致

You have to use DeviceAdminReceiver class in your app for example例如,您必须在您的应用程序中使用 DeviceAdminReceiver 类

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您可以在我的存储库https://github.com/ArtemBotnev/AdminApp/blob/master/app/src/main/java/ru/rs/adminapp/AdminReceiver.kt 中查看完整示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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