Usb Device Access Pop-Up Suppression

Android App Won't Remember USB Permission

We ended up opening the app automatically when the USB is inserted into the phone, because our project deals with the app being open all day.

The app only asks for permission to use the USB once for the phone and remembers it now, as long as the user connects the USB before opening the app and the phone is unlocked. The phone even remembers the permission after the phone is restarted.

This is kind of a work around, but it works for our needs. Hopefully this will help some others with the same problem.

USB pop-up window?

It is NOT possible;

You wrote: " I want to program the usb so that any PC that the device is connected "

You'd rather program the PC not the USB

USB is a storage device only. Unfortunatelly you can't program all the PC's that USb might get into

The ONLY way this might be (yes it won't work in every case I guarantee) be tweaked is to have autorun.inf file in the USB pointing to a program on the USB that displays the message you want.
[Autorun]

Open=msg.exe

Due to most modern operating systems have tons of blocking mechanism to stop autorun programs this message has very slight chance to appear

USB Host Mode - device access permission granted but not remembered

This is a dup of USB device access pop-up supression?. Basically the answer is to use an intent-filter on USB_DEVICE_ATTACHED and steer clear of the RequestPermission USB Host Mode API call.

Remove USB Accessory permission dialog

According to the Android USB host documentation, your application has permission to access the device until the device is disconnected. This question provides a solution to suppress the permission dialog. Create an intent filter in your manifest file and provide the device information in an xml file. This would enable enumerating the device using a broadcast receiver.

Another reference is this question. The latter is meant for rooted devices and I haven't tried it personally.

Edit:

Manifest File: I register my Broadcast Receiver in the manifest file.

<receiver android:name="MyReceiver">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</receiver>

For the sake of convenience, I have my Broadcast Receiver in a separate class:

public class PmrtReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();
if(UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)){

Toast.makeText(context, "Device Detected",Toast.LENGTH_LONG).show();

} else if(UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)){

Toast.makeText(context, "Device Detached",Toast.LENGTH_LONG).show();

}

}

};

I did not have to do anything else to suppress the permission dialog.

Look into the USB Missile Launcher example from the Android Samples. Your device filtr should be something like this:

<?xml version="1.0" encoding="utf-8"?>

<resources>
<usb-device vendor-id="1234" product-id="5678" />
</resources>

You have the VID and PID as hexadecimal numbers.



Related Topics



Leave a reply



Submit