The right way to find SD-Card path and in work with its files

28
July 11, 2019, at 7:50 PM

I am creating a file manager for android and the last thing I have to do is access to sd-card files.

And I have some questions about it.

  1. I use Environment.getExternalStorageDirectory() to get internal storage path (/storage/emulated/0/). And as I know, it's not a right way because the method can return either internal storage or sd-card path. So what is the right way to get internal storage?

  2. Also use the following code to get sd-card path:

    String sd = context.getExternalFilesDirs("")[1].getAbsolutePath();
    mPath = sd.substring(1,sd.indexOf("/Android/"));
    

With this code, I get the right way for sd but I can't work with files on sd-card (I get a permissions error but I have all necessary permissions).

So, the questions are: what are the correct ways of getting internal storage path and sd-card path on android (and how can I interact with sd-card files if File class doesn't work there)?

READ ALSO
How to make two toolbars? [on hold]

How to make two toolbars? [on hold]

I am trying to make this kind of activity:

20
Is there a way to put a video into an AlertDialog? [duplicate]

Is there a way to put a video into an AlertDialog? [duplicate]

This question already has an answer here:

18
Android : How to integrate Push Notification to an already existing app?

Android : How to integrate Push Notification to an already existing app?

How to integrate Push Notification to an already existing android app?

26
Unexpected behaviour of onChildAdded stream in firebase_database

Unexpected behaviour of onChildAdded stream in firebase_database

I've recently started learning Flutter and the FlutterFire pluginsYesterday I was working with the firebase_database plugin which allows adding Firebase Realtime Database to Flutter

44