Android Question USB Library Request Permission dialog supression

walterf25

Expert
Licensed User
Longtime User
Hello all, does anybody know if it is possible to suppress or keep the permission dialog from coming up?, I came across this but don't really understand it.

B4X:
private static final String ACTION_USB_PERMISSION =
    "com.android.example.USB_PERMISSION";
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (ACTION_USB_PERMISSION.equals(action)) {
            synchronized (this) {
                UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

                if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                    if(device != null){
                      //call method to set up device communication
                  }
                }
                else {
                    Log.d(TAG, "permission denied for device " + device);
                }
            }
        }
    }
};

I know that you can add a device_filter.xml file to only ask for permission the first time, but i would really like to fully automate the process since the app will be running in a android dongle and it will be inside a sealed box and customer's will not have any access to the device, therefore i need to make this work so that if for some reason the customer unplugs or powers down the device that it will regain usb connection automatically.

Also a previous app i made which uses the usbserial library works different, what i mean by different is that when i connect the usbserial cable to the device the phone automatically pops up a dialog that asks what app i want to run, now i'am using the usbhost library and it works different, does anyone know why?

Any advice or help will be greatly appreciated.

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
This Java code will not suppress the dialog. It only catches the result.
Hi Erel, is there a way to suppress the permission dialog then?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…