删除Android上特定设备的授予权限

时间:2014-05-15 14:30:04

标签: android permissions

我有一个应用程序,它在onCreate事件方法中检查特定的USB设备。当我通过查看其设备和供应商ID找到我的设备时,我会立即向用户询问USB许可,如下所示:

        UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
        HashMap<String, UsbDevice> map = usbManager.getDeviceList();
        Iterator<UsbDevice> it = map.values().iterator();
        while(it.hasNext())
        {
          UsbDevice device = it.next();
          if (device.getVendorId() == 1155 && device.getProductId() == 22336)
          {
              Log.e("Jetty", "Token found.");
              final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
              PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
              usbManager.requestPermission(device, mPermissionIntent);
          }
        }

到目前为止,一切都很完美。如果用户授予权限,则应用程序可以与设备通信。问题是,每次启动应用程序时,我都想请求许可。我的意思是我不想在用户之前是否授予许可。我想在每次启动应用程序时一次又一次地询问用户。简而言之,我希望之前清除或删除已接受或授予的权限,并且每次都要求它。

我试过了,但它没有用。

final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
mPermissionIntent.cancel();
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
usbManager.requestPermission(device, mPermissionIntent);

我应该如何清除给定的权限或在另一方面解决此问题?

0 个答案:

没有答案