Xamarin | Android | COSU错误

Xamarin | Android | COSU错误,第1张

概述我正在尝试创建一个COSU设备.它将是我公司销售的硬件,它运行由我们开发的单个应用程序.我已经浏览了许多教程,试图为此设置一个概念验证.我目前有以下内容.在我的AndroidManaifest.xml中然后……<applicationandroid:allowBackup="true"android:label="@string/app_name"an

我正在尝试创建一个COSU设备.它将是我公司销售的硬件,它运行由我们开发的单个应用程序.我已经浏览了许多教程,试图为此设置一个概念验证.

我目前有以下内容.

在我的AndroidManaifest.xml中

然后……

<application androID:allowBackup="true" androID:label="@string/app_name" androID:keepScreenOn="true" >    <receiver   androID:name="Deviceadmin"                androID:label="@string/sample_device_admin"                androID:description="@string/sample_device_admin_description"                androID:permission="androID.permission.BIND_DEVICE_admin">        <intent-filter>            <action androID:name="androID.app.action.DEVICE_admin_ENABLED" />        </intent-filter>        <device-admin>            <uses-policIEs>                <limit-password />                <watch-login />                <reset-password />                <force-lock />                <wipe-data />            </uses-policIEs>        </device-admin>    </receiver>    <uses-permission androID:name="androID.permission.MANAGE_DEVICE_adminS" />    <intent-filter>        <action androID:name="androID.intent.action.MAIN" />        <category androID:name="androID.intent.category.HOME" />        <category androID:name="androID.intent.category.DEFAulT" />    </intent-filter></application>

在device_admin_receiver.xml中

<?xml version="1.0" enCoding="utf-8"?><device-admin xmlns:androID="http://schemas.androID.com/apk/res/androID">    <uses-policIEs>        <limit-password />        <watch-login />        <reset-password />        <force-lock />        <wipe-data />    </uses-policIEs></device-admin>

Deviceadmin.cs

using System;using System.Collections.Generic;using System.linq;using System.Text;using AndroID.App;using AndroID.App.admin;using AndroID.Content;using AndroID.OS;using AndroID.Runtime;using AndroID.VIEws;using AndroID.Widget;namespace CB.App{    public class Deviceadmin : DeviceadminReceiver    {    }}

最后是MainActivity.cs的OnCreate

protected overrIDe voID OnCreate(Bundle savedInstanceState)    {        base.OnCreate(savedInstanceState);        Window.DecorVIEw.systemUIVisibility = (StatusbarVisibility)flags;        // Setup the collection and register implementations        IServiceCollection coll = new ServiceCollection();        RegisterDependencIEs(coll);        // Build the global services        ServiceRegistrationHelper.RegisterCoreServices(coll);        // Register the provIDe with the GlobalServices        GlobalServices.RegisterServiceProvIDer(coll.BuildServiceProvIDer(new ServiceProvIDerOptions()));        // Set our vIEw from the "main" layout resource        SetContentVIEw(Resource.Layout.Main);        DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager)this.GetSystemService(Activity.DevicePolicyService);        // get this app package name        Componentname mDPM = new Componentname(this, typeof(Deviceadmin).name);        if( myDevicePolicyManager.IsDeviceOwnerApp(this.Packagename))        {            //myDevicePolicyManager.ClearDeviceOwnerApp(this.Packagename);            String[] packages = { this.Packagename };            myDevicePolicyManager.SetLockTaskPackages(mDPM, packages);            StartLockTask();            SetUpClock();            displayHome();        }        else        {            Toast.MakeText(this.ApplicationContext, "Not Owner", ToastLength.Long).Show();        }    }

在ADB Shell中,我运行命令dpm set-device-owner com.companyname.productname / .Deviceadmin并收到Success:设备所有者设置为package componentinfo {com.companyname.productname / com.companyname.productname.Deviceadmin} Active admin set组件{com.companyname.productname / com.companyname.productename.Deviceadmin}

它构建和部署但是当它到达生产线时

myDevicePolicyManager.SetLockTaskPackages(mDPM, packages);

它抛出错误java.lang.SecurityException:没有活动的admin组件信息(com.lathem.cumberland / Deviceadmin)

我错过了什么?

解决方法:

删除< device-admin>来自接收器的部分,应通过单独的xml资源引用,或者通过硬编码接收器清单部分中的元数据部分或通过类属性:

[broadcastReceiver(    name = "com.sushihangover.cosu.DeviceadminReceiver",     Label = "StackOverflow",    Permission = "androID.permission.BIND_DEVICE_admin",    Exported = true)][MetaData("androID.app.device_admin", Resource = "@xml/device_admin_receiver")][IntentFilter(new[] {     "androID.intent.action.DEVICE_admin_ENABLE",     "androID.intent.action.PROfile_PROVISIONING_COMPLETE",     "androID.intent.action.BOOT_COMPLETED" })]public class MyDeviceadminReceiver : DeviceadminReceiver {}

使用java类名,而不是C#名:

Componentname mDPM = new Componentname(this, java.lang.class.FromType(typeof(DeviceadminReceiver)));

注意:根据我对DeviceadminReceiver子类的Java名称的使用,dpm set-device-owner将是:

adb shell dpm set-device-owner com.sushihangover.cosu/com.sushihangover.cosu.DeviceadminReceiver
总结

以上是内存溢出为你收集整理的Xamarin | Android | COSU错误全部内容,希望文章能够帮你解决Xamarin | Android | COSU错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1118571.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存