gpt4 book ai didi

android - 在使用 Device Policy Manager 时需要帮助

转载 作者:行者123 更新时间:2023-12-04 17:53:29 26 4
gpt4 key购买 nike

早上好,我需要 StackOverflow 的某个人的帮助来创建我的信息亭模式应用程序。

我试图找到创建信息亭模式应用程序的解决方案,但没有任何效果。

我需要使用 Xamarin 在 Visual Studio 中开发此应用。

我的要求是隐藏主页栏。我试过这个:

[Activity(Label = "app", MainLauncher = true, ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Theme = "@android:style/Theme.Holo.Light.NoActionBar.Fullscreen")]

这会隐藏栏,但是当有人将栏拖到顶部时它会重新出现并且用户可以将其关闭。

我找到了适用于 Java 的解决方案,但无法转换为 Xamarin。

你能帮帮我吗?

问候,安德里亚

更新:

我试过这个:

[BroadcastReceiver(Permission = "android.permission.BIND_DEVICE_ADMIN")]
[MetaData("android.app.device_admin", Resource = "@xml/device_admin")]
[IntentFilter(new[] { "android.app.action.DEVICE_ADMIN_ENABLED", Intent.ActionMain })]
public class DeviceAdmin : DeviceAdminReceiver
{

}

我试图通过 adb 启动这个命令,但它给我这个错误:

C:\Users\user\AppData\Local\Android\sdk\platform-tools>adb shell dpm set-device-owner app.app/.MainActivity
usage: dpm [subcommand] [options]
usage: dpm set-active-admin [ --user <USER_ID> ] <COMPONENT>
usage: dpm set-device-owner <COMPONENT>
usage: dpm set-profile-owner [ --user <USER_ID> ] <COMPONENT>

dpm set-active-admin: Sets the given component as active admin for an existing user.

dpm set-device-owner: Sets the given component as active admin, and its package as device owner.

dpm set-profile-owner: Sets the given component as active admin and profile owner for an existing user.

Error: Unknown admin: ComponentInfo{Tabdealer.Tabdealer/Tabdealer.Tabdealer.MainActivity}

我的 Activity 是:

public class MainActivity : Activity
{
[BroadcastReceiver(Permission = "android.permission.BIND_DEVICE_ADMIN")]
[MetaData("android.app.device_admin", Resource = "@xml/device_admin")]
[IntentFilter(new[] { "android.app.action.DEVICE_ADMIN_ENABLED", Intent.ActionMain })]
public class DeviceAdmin : DeviceAdminReceiver
{

}

设备管理员.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 />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>

但是我不知道如何使用DevicePolicyManager

最佳答案

我只做了几天,但我想我可以帮助你。

我假设您在代码中注册了您的设备管理接收器并且没有共享它。如果不是,您需要执行类似的操作。

DevicePolicyManager devicePolicyManager = (DevicePolicyManager)GetSystemService(Context.DevicePolicyService);
ComponentName deviceAdminComponent = new ComponentName(this, Java.Lang.Class.FromType(typeof(DeviceAdmin)));
Intent intent = new Intent(DevicePolicyManager.ActionAddDeviceAdmin);
intent.PutExtra(DevicePolicyManager.ExtraDeviceAdmin, deviceAdminComponent);
intent.PutExtra(DevicePolicyManager.ExtraAddExplanation, "Device administrator");
StartActivity(intent);

我认为你错误地定义了这个命令。

adb shell dpm set-device-owner app.app/.MainActivity

adb shell dpm set-device-owner之后应该是PackageName/.DeviceAdminReceiverName

如果您右键单击 android 项目并查看 Android Manifest 选项卡,它应该会告诉您包名称。如果你说 app.app 那么你的第一部分是正确的。在四处寻找时,请确保您的 device_admin.xml 在 vi​​sual studio 中被标记为 Android 资源。

调试您的 deviceAdminComponent 以确保您使用全名。你的会有所不同,但它看起来像这样。

enter image description here

然后在 adb shell 命令中包含您的 DeviceAdmin 的全名。

adb shell dpm set-device-owner app.app/md50db01e1d47836fa6db48b854d43dd279.DeviceAdmin

现在,下次您重新启动应用程序时,所有管理功能都将可用。比如;

 devicePolicyManager.SetLockTaskPackages(deviceAdminComponent, new[] { PackageName });
StartLockTask();

最后你可以用标志隐藏状态栏了。不过,这不需要任何管理权限。

Window.AddFlags(WindowManagerFlags.Fullscreen);
Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);

关于android - 在使用 Device Policy Manager 时需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42398107/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com