ADB Shell DPM设定设备所有者具有Unity问题



我正在尝试通过使用COSU(企业拥有的一次用途(功能来使Unity应用进入售货亭模式。

我的计划是首先使用Android让事情正常工作,因此我遵循了Google Code Labs提供的教程

我完成了这项工作后,我的计划是弄清楚如何将其集成到我的Unity项目中。我跟着这个YouTube视频显示了如何制作可以从Unity调用的插件。

构建项目时,我尝试执行以下命令

adb shell dpm set-device-owner com.modalvr.unityplugin/.DeviceAdminReceiver

但是,我不断收到以下错误

Error: Unknown admin: ComponentInfo{com.modalvr.unityplugin/com.modalvr.unityplugin.DeviceAdminReceiver}

我想知道Unity是否正确合并了AndroidManifest.xml文件。这是我的androidManifest.xml文件。

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.modalvr.unityplugin">
    <application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true">
        <receiver
            android:name="com.modalvr.unityplugin.DeviceAdminReceiver"
            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_admin_receiver" />
            <intent-filter>
                <action android:name="android.intent.action.DEVICE_ADMIN_ENABLED"/>
                <action android:name="android.intent.action.PROFILE_PROVISIONING_COMPLETE"/>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>

我将其复制为" jar file.jar文件">

我能够在插件中成功调用函数,因此插件似乎正确设置了。

供参考,这是我的c#代码,该代码在插件中调用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LockManager : MonoBehaviour {
#if UNITY_ANDROID
    private AndroidJavaObject playerActivityContext = null;
#endif
    public void SaveContext() {
#if UNITY_ANDROID
        // First, obtain the current activity context
        using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
        playerActivityContext = actClass.GetStatic<AndroidJavaObject>("currentActivity");
        }
        var plugin = new AndroidJavaClass("com.modalvr.unityplugin.PluginClass");
        plugin.CallStatic<bool>("setContext", playerActivityContext);
#endif
    }
    public void LockButtonClicked() {
#if UNITY_ANDROID
        SaveContext();
        var plugin = new AndroidJavaClass("com.modalvr.unityplugin.PluginClass");
        bool retVal = plugin.CallStatic<bool>("lock", 7);
#endif
    }
public void UnlockButtonClicked() {
#if UNITY_ANDROID
        SaveContext();
        var plugin = new AndroidJavaClass("com.modalvr.unityplugin.PluginClass");
        bool retVal = plugin.CallStatic<bool>("unlock", 7);
#endif
    }
}

这是定义这些功能的Java类。

package com.modalvr.unityplugin;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
public class PluginClass {
    private static Context context;
    public static boolean setContext(Context ctx) {
        context = ctx;
        return true;
    }
    public static boolean lock(int number) {
        Log.d("SOME TAG", "onReceive Lock");
        Activity activity = (Activity) context;
        activity.startLockTask();
        return true;
    }
    public static boolean unlock(int number) {
        Log.d("SOME TAG", "onReceive Unlock");
        Activity activity = (Activity) context;
        activity.stopLockTask();
        return true;
    }
}

看起来Unity生成了2个XML文件,将其放入临时/stagingarea

androidmanfist.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ModalVR.KioskPluginTest" xmlns:tools="http://schemas.android.com/tools" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

和androidManifest-main.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ModalVR.KioskPluginTest" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal" android:versionName="1.0" android:versionCode="1">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />
</manifest>

在这两个文件中,我都没有看到我的Android插件AndroidManifest.xml的内容,我想这是问题所在。我需要做一些使清单文件合并的操作吗?

并且为了完整性,这是

deviceadminreceiver.java

package com.modalvr.unityplugin;
import android.content.ComponentName;
import android.content.Context;
/**
 * Handles events related to the managed profile.
 */
public class DeviceAdminReceiver extends android.app.admin.DeviceAdminReceiver {
    private static final String TAG = "DeviceAdminReceiver";
    /**
     * @param context The context of the application.
     * @return The component name of this component in the given context.
     */
    public static ComponentName getComponentName(Context context) {
        return new ComponentName(context.getApplicationContext(), DeviceAdminReceiver.class);
    }
}

事先感谢您的任何帮助。约翰·劳里(John Lawrie(

我需要做一些使清单文件合并的事情吗?

是。

如果您将Java插件编译为 .aar 软件包,则Unity的清单将自动合并。如果将其构建为 .jar 文件,则必须手动将清单放在统一的正确文件夹中,以便在构建过程中可以将其合并到您的程序中。

>

您当前正在以 .jar 库构建,因此下面是放置清单的位置:

androidManifest.xml 文件放在<ProjectName>AssetsPluginsAndroid文件夹中。确保拼写 AndroidManifest 以及正确放置的文件夹名称。就是这样。

最新更新