【问题标题】:Disallow MTP connection by code android Lollipop通过代码 android Lollipop 禁止 MTP 连接
【发布时间】:2015-12-27 10:20:44
【问题描述】:

我正在尝试通过 API 级别 22 中的代码禁用与 PC 的 MTP 连接。

这个方法使用了21之前的Google API:

public void setUserRestriction (String key, boolean value)

但在 API 级别 22 中,该方法更改为:

public void addUserRestriction (ComponentName admin, String key)

在类中

DevicePolicyManager.

我的主要问题是我找不到可以执行此操作的设备管理员 (或者也许我不知道如何创建它) 我有钥匙:

DISALLOW_USB_FILE_TRANSFER 

但我不知道需要使用的 ComponentName...

有人试过吗?我在我的应用程序中调用此代码。 谢谢!

【问题讨论】:

  • 你在吗?有帮助吗?
  • 其实我是这样处理的:setprop(sys.usb.config) to "none"

标签: android android-5.1.1-lollipop device-admin


【解决方案1】:

您应该已经有一个 DeviceAdminReceiver 子类,您只需要将它作为 ComponentName 对象传递。

public void addUserRestriction (ComponentName admin, String key)
Parameters
   admin - Which DeviceAdminReceiver this request is associated with.
   key   - The key of the restriction. See the constants in UserManager for the list of keys.

这样称呼它:

addUserRestriction(new ComponentName(context, MyDeviceAdminReceiver.class), 
                                   UserManager.DISALLOW_USB_FILE_TRANSFER);

文档中有一个示例 DeviceAdminReceiver: http://developer.android.com/reference/android/app/admin/DeviceAdminReceiver.html

【讨论】:

  • Caused by: java.lang.SecurityException: No active admin 当调用addUserRestriction
猜你喜欢
  • 2011-11-03
  • 1970-01-01
  • 2012-09-14
  • 1970-01-01
  • 1970-01-01
  • 2014-12-22
  • 2012-02-25
  • 2020-09-11
相关资源
最近更新 更多