最终目的是让设备处于“展示模式”。
他们 说,为实现应用成为设备所有者,不需要NFC或root权限。我还没有看到这种方法的完整示例,但让我们试试:
adb shell dpm set-device-owner <package>/.<ReceiverImplementation>
应该这样做...因此我这样做了,得到:
java.lang.SecurityException:
Neither user 2000 nor current process has android.permission.BIND_DEVICE_ADMIN.
因此,以下代码返回false。
((DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE))
.isDeviceOwnerApp(getApplicationContext().getPackageName())
这个STO问题提出了类似的问题,但没有具体说明失败的原因。
清单文件和其他源代码大多受到这个谷歌示例的启发。
<manifest
package="com.example.android.deviceowner"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0">
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver
android:name=".DeviceOwnerReceiver"
android:description="@string/app_name"
android:label="@string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_owner_receiver"/>
<intent-filter>
<action android:name="android.app.action.ACTION_DEVICE_ADMIN_ENABLED"/>
</intent-filter>
</receiver>
</application>
</manifest>
我目前正尝试使用LG G Pad设备。
<uses-permission>
,以便pm
(包管理器)将其作为应用程序级别的权限捕获。 - Aaron Gillion