how to programmatically enable and disable USB in android Application

后端 未结 3 1980
误落风尘
误落风尘 2021-01-06 09:18

in my application i want to enable / disable the USB connection in the phone or tab(Android based) programmatically.I googled , but did not find any solution.If it is possib

相关标签:
3条回答
  • 2021-01-06 09:45

    I know it is too late but it would be helpful to others.. In API 12 Android 3.1 or higher , there is a UsbManager class has been introduced,

    Check this link. http://developer.android.com/reference/android/hardware/usb/UsbManager.html

    0 讨论(0)
  • 2021-01-06 10:03

    This is not possible from the Android SDK.

    0 讨论(0)
  • 2021-01-06 10:03

    This is possible, but your application should own the device, by owning the device you can use the DevicePolicyManager.addUserRestriction method, as follows:

    DevicePolicyManager devicePolicyManager =
                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    
    if (devicePolicyManager != null && isDeviceOwnerApp(context)) {
       devicePolicyManager.addUserRestriction(componentName, UserManager.DISALLOW_USB_FILE_TRANSFER);
    }
    
    0 讨论(0)
提交回复
热议问题