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
Generate APK File from Aab File (Android App Bundle)
How to Start/ Launch Application at Boot Time Android
How to Set Internet Options for Android Emulator
How to Avoid "Illegalstateexception: Scrollview Can Host Only One Direct Child"
Blur or Dim Background When Android Popupwindow Active
Android Get Orientation of a Camera Bitmap? and Rotate Back -90 Degrees
How to Get Recent Tasks on Android "L"
Edittext Loses Content on Scroll in Listview
How to Get City Name from Latitude and Longitude Coordinates in Google Maps
Recyclerview Itemtouchhelper Buttons on Swipe
How to Make an Android App to Always Run in Background
Admob Error in Eclipse for Android:Configchanges
Removing Log Call Using Proguard
Use Tab with New Toolbar (Appcompat V7-21)
Monodroid: Error When Calling Constructor of Custom View - Twodscrollview
How to Retrieve Style Attributes Programmatically from Styles.Xml