Xamarin自助服务终端应用

时间:2017-02-22 17:14:36

标签: android xamarin xamarin.android

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 活动}

我的活动是:

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。

1 个答案:

答案 0 :(得分: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 标签下查看,它将告诉您Package Name。如果您说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);