设备所有者在非根设备(Android L)上,没有NFC,使用adb shell,dpm set-device-owner

前端之家收集整理的这篇文章主要介绍了设备所有者在非根设备(Android L)上,没有NFC,使用adb shell,dpm set-device-owner前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这里的最终目的是在’kiosk mod’中设置一个设备.

They say您不需要NFC也不需要生根来实现应用程序成为device owner.我还没有看到这个方法的完整示例但是让我们试试:

  1. adb shell dpm set-device-owner <package>/.<ReceiverImplementation>

应该这样做…所以我这样做,并得到:

  1. java.lang.SecurityException:
  2. Neither user 2000 nor current process has android.permission.BIND_DEVICE_ADMIN.

因此,以下代码返回false.

  1. ((DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE))
  2. .isDeviceOwnerApp(getApplicationContext().getPackageName())

This STO question提出了类似的问题,但未指明实际的失败.

清单文件和源代码的其余部分主要来自this google sample

  1. <manifest
  2. package="com.example.android.deviceowner"
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:versionCode="1"
  5. android:versionName="1.0">
  6.  
  7. <application
  8. android:allowBackup="true"
  9. android:icon="@drawable/ic_launcher"
  10. android:label="@string/app_name"
  11. android:theme="@style/AppTheme">
  12.  
  13. <activity
  14. android:name=".MainActivity"
  15. android:label="@string/app_name">
  16. <intent-filter>
  17. <action android:name="android.intent.action.MAIN"/>
  18. <category android:name="android.intent.category.LAUNCHER"/>
  19. </intent-filter>
  20. </activity>
  21.  
  22. <receiver
  23. android:name=".DeviceOwnerReceiver"
  24. android:description="@string/app_name"
  25. android:label="@string/app_name"
  26. android:permission="android.permission.BIND_DEVICE_ADMIN">
  27. <Meta-data
  28. android:name="android.app.device_admin"
  29. android:resource="@xml/device_owner_receiver"/>
  30. <intent-filter>
  31. <action android:name="android.app.action.ACTION_DEVICE_ADMIN_ENABLED"/>
  32. </intent-filter>
  33. </receiver>
  34.  
  35. </application>
  36.  
  37. </manifest>

我试图这样做的设备目前是LG G Pad.

解决方法

您的清单文件似乎正确.
您应该知道,在执行此命令时,它可能来自您系统的状态.在成功运行dpm命令之前,应检查许多点:

>确保您的应用已经安装,就像任何其他休闲应用程序一样
>确保在使用之前没有为当前用户设置任何帐户(确保在“设置”>“帐户”中未设置任何帐户).
>不应该有已注册的现有设备所有者

最好的事情(这就是我在实验时所做的)是完全重启工厂并避免大多数配置步骤(除了强制性步骤“配置Wi-Fi”和“名称”),并且不关联任何Google帐户.
配置完成后,您肯定处于干净状态.
然后,

>激活调试
>使用IDE安装您的应用程序(或使用pm安装…)
>运行命令adb shell dpm set-device-owner …

我写了an article explaining most of these steps on my blog,看看它,它可能对你的情况有用.

猜你在找的Android相关文章