I'm trying to read files from a USB storage device connected to my Google Pixel. I'm currently using this method to select the path of the drive so I can query it for its contents
private static final String TAG = "MainActivity";
private static final int REQUEST_CHOOSE_DRIVE = 1;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.text);
Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(i, REQUEST_CHOOSE_DRIVE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CHOOSE_DRIVE) {
Uri uri = data.getData();
}
}
However, the Uri looks something like /tree/...
which doesn't seem to be a real path in the Android file system (verified via adb shell
). How can I use this uri
to query the contents of a portable storage device? I tried using the answer given here but the linked function returns null
.