How to get path mounted usb device in android?
<p>I write a program,which contains broadcast receiver to catch <strong>ACTION_MEDIA_MOUNTED</strong>,but it works not on all devices. In example: my Meizu m2 note has otg support , and device can open a flash storage,but in my application it not works(no open). In my code,I need to get directory(mass storage directory) path to write or read file.</p>

<p>my broadcast:
public class UsbReceiver extends BroadcastReceiver {</p>

<pre><code>private static final String ACTION_USB_PERMISSION = "com.poudanen.usbchecker.USB_PERMISSION";

@Override
public void onReceive(final Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)) {
        Toast.makeText(context, "Media device connected", Toast.LENGTH_SHORT).show();
        Uri uriFile = intent.getData();
        File dir = new File(uriFile.getPath());
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        prefs.edit().putString("path", uriFile.getPath()).apply();
        Toast.makeText(context, "Media device connected", Toast.LENGTH_SHORT).show();
        if (dir.canRead()) {

        //other code
        }
    }}
</code></pre>