简体   繁体   English

使用adb shell dpm set-device-owner的无根设备(Android L)(无NFC)上的设备所有者

[英]Device owner on a nonrooted device (Android L), without NFC, using adb shell, dpm set-device-owner

Final intention here is to have a device in 'kiosk mod'. 这里的最终目的是在“ kiosk mod”中安装一个设备。

They say you don't need NFC nor rooting to achieve application becoming device owner . 他们 说,您既不需要NFC也无需扎根,即可使应用程序成为设备所有者 I've yet to see a full example of this method but lets try: 我还没有看到这种方法的完整示例,但请尝试:

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

should do... So I do so, and get: 应该做...所以我这样做,并得到:

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

Following code, therefore, returns false. 因此,以下代码返回false。

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

This STO question poses a similar question but doesn't specify an actual failure.. 此STO问题提出了类似的问题,但未指定实际失败。

Manifest file and the rest of the source is mostly inspired from this google sample 清单文件和其他来源的主要灵感来自此google示例

<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>

Device I am trying to do this currently is LG G Pad. 我目前正在尝试执行此操作的设备是LG G Pad。

Your manifest file seems correct. 您的清单文件似乎正确。 You should be aware that it may come from the state of your system when you are executing this command. 您应该知道,它可能来自执行此命令时的系统状态。 Many points should be checked before running the dpm command successfully : 成功运行dpm命令之前,应检查许多点:

  • Make sure your app is already installed, like any other casual app 确保您的应用已经安装,就像其他休闲应用一样
  • Make sure that no account is already set for the current user (make sure no account is set in Settings > Accounts) before its use. 在使用当前用户之前,请确保尚未为当前用户设置任何帐户(确保在“设置”>“帐户”中未设置任何帐户)。
  • there shouldn't be an existing device owner already registered 不应已经注册了现有的设备所有者

The best thing to do (That's what I did when experimenting indeed) is to completely factory-reboot your phone and avoid most configuration steps (except the mandatories steps "configure Wi-Fi", and "Name"), and do not associate any Google account . 最好的做法(实际上是我在做实验时所做的事情)是完全恢复出厂设置,并避免执行大多数配置步骤(强制步骤“配置Wi-Fi”和“名称”除外),并且不要将任何关联Google帐户
Once provisioned, you are sure to be in a clean state. 设置后,您一定会处于干净状态。 Then, 然后,

  1. Activate Debugging 激活调试
  2. install your app with your IDE (or with pm install ...) 使用您的IDE安装您的应用程序(或使用pm install ...)
  3. run the command adb shell dpm set-device-owner ... 运行命令adb shell dpm set-device-owner ...

I've written an article explaining most of these steps on my blog , take a look at it, it may be useful in your case. 我在博客上了一篇文章,解释了其中的大多数步骤 ,请看一下它,这可能对您有用。

I am not sure if this is going to help you, but if not you, maybe someone else will use this solution. 我不确定这是否会对您有所帮助,但是如果您不满意,也许其他人会使用此解决方案。 I had a very similar problem with Samsung Tab A. I could not set the ownership to my application. 我在Samsung Tab A上遇到了非常相似的问题。我无法为应用程序设置所有权。 Always while running: 始终在运行时:

adb shell dpm set-device-owner cy.com.myapp/.AdminReceiver

I was getting: 我得到:

java.lang.SecurityException: Neither user 2000 nor current process has 
com.sec.enterprise.permission.MDM_PROXY_ADMIN_INTERNAL.

After long search I finally found that I needed to add to my manifest permissions special permissions of Samsung: 经过长时间的搜索,我终于发现我需要在清单权限中添加Samsung的特殊权限:

<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK" />

That did the trick and now my app can go to the kiosk mode on demand. 做到了这一点,现在我的应用程序可以按需进入信息亭模式。 Possibly you are looking at a similar problem - maybe there is one or more permission setting that you need to set for your LG. 您可能正在寻找类似的问题-可能需要为LG设置一个或多个权限设置。 My solution worked for a non-rooted device (and obviously without any account added - fresh after factory reset). 我的解决方案适用于无根设备(显然没有添加任何帐户-恢复出厂设置后仍有效)。

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

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