Xamarin自助服务终端应用

问题描述 投票:1回答:1

Goodmorning,我需要stackoverflow中的某人帮助创建我的kios模式应用程序。我试图找到解决方案来创建自助服务终端模式应用程序,但没有解决方案。我需要使用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-d
evice-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 u
ser.

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  own
er for an existing user.

错误:未知管理员:ComponentInfo {Tabdealer.Tabdealer / Tabdealer.Tabdealer.Main 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
        { 

        }

deviceadmin.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。

android xamarin xamarin.android
1个回答
0
投票

我只是在这几天,但我想我可以帮助你。

我假设你在代码中注册了你的设备管理员接收器并且没有共享它。如果不是,你需要做这样的事情。

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在visual 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);
© www.soinside.com 2019 - 2024. All rights reserved.