Hi,
I am not able to read the files from the USB drive which is connected to the android device using 7.1.1.
MY manifest file has all the permissions
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MEDIA_WRITE_STORAGE" />
<uses-permission android:name="android.permission.MEDIA_READ_STORAGE" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-feature android:name="android.hardware.usb.host" />
Activity Code
var mPermissionIntent = PendingIntent.GetBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
UsbManager usbManager = (UsbManager)GetSystemService(Context.UsbService);
var deviceList = usbManager.DeviceList;
IEnumerable<UsbDevice> deviceIterator = deviceList.Values.AsEnumerable();
if (deviceIterator.Count() > 0)
{
UsbDevice device = deviceIterator.ElementAt(0);
usbManager.RequestPermission(device, mPermissionIntent);
if (usbManager.HasPermission(device))
{
if (usbManager.HasPermission(device))
{
System.Diagnostics.Debug.WriteLine("HasPermission");
UsbDeviceConnection connection = usbManager.OpenDevice(device);
if( connection != null)
{
System.Diagnostics.Debug.WriteLine(" connection is not null");
var model = device.DeviceName;
string inline = null;
BufferedReader reader = null;
reader = new BufferedReader(new FileReader("/mnt/media_rw/C227-875D/test/hello.txt"));
System.Diagnostics.Debug.WriteLine("no exception occured");
while ((inline = reader.ReadLine()) != null)
{
System.Diagnostics.Debug.WriteLine(inlne);
}
}
}
Exception
01-04 23:51:30.309 I/MonoDroid( 2845): UNHANDLED EXCEPTION:
01-04 23:51:30.382 I/MonoDroid( 2845): Java.IO.FileNotFoundException: /mnt/media_rw/C227-875D/test/hello.txt (Permission denied)
In the above code, it says it has permissions, but just that I get an exception while reading the file .
Please help!!