如何以编程方式为事件注入器设置权限?我正在尝试通过模拟“发送”键来自动接听来电。在模拟器上,事件注入器工作得很好,但是,当我在实际设备上运行代码时,它无法工作。
问问题
254 次
2 回答
4
RIM API 不允许以编程方式设置权限。您只能请求权限,显示权限请求屏幕,用户必须手动设置权限。
没有解决方法,这是一种安全措施。否则,恶意软件可能会设置任意权限并为所欲为。
于 2012-08-24T06:06:46.680 回答
1
像这样的东西会检查权限(如果您的应用程序已经运行,并且用户已经接受了权限),或者如果它们尚未被接受,则请求它们。根据您的应用程序的其他功能,您可能只需要请求PERMISSION_INPUT_SIMULATION
. 我下面的代码也显示了一些其他权限。
/** @return true if the user has accepted permissions requests */
public boolean hasPermissions() {
ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
ApplicationPermissions original = apm.getApplicationPermissions();
if ((original.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == ApplicationPermissions.VALUE_ALLOW)
&& (original.getPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS) == ApplicationPermissions.VALUE_ALLOW)
&& (original.getPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION) == ApplicationPermissions.VALUE_ALLOW)
&& (original.getPermission(ApplicationPermissions.PERMISSION_INTERNET) == ApplicationPermissions.VALUE_ALLOW)
&& (original.getPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK) == ApplicationPermissions.VALUE_ALLOW))
{
return true;
} else {
return false;
}
}
/** @return true if the user has accepted / granted permissions */
public boolean checkPermissions() {
if (!hasPermissions()) {
ApplicationPermissions permRequest = new ApplicationPermissions();
permRequest.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
permRequest.addPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS);
permRequest.addPermission(ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION);
permRequest.addPermission(ApplicationPermissions.PERMISSION_INTERNET);
permRequest.addPermission(ApplicationPermissions.PERMISSION_SERVER_NETWORK);
return ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permRequest);
} else {
return true;
}
}
于 2012-08-24T21:17:57.557 回答