user1648695
user1648695

Reputation: 3

Accessing internal/external memory in android

I am pretty new to android programming and I need your help in proceeding further in my application. I wanted to access the internal or external memory of android phones through my application with both write and read permissions. I wanted to give users a choice as to which memory to be used in the application.

I'll be thankful to anyone who can help me.

Upvotes: 0

Views: 3239

Answers (2)

Narendra Pal
Narendra Pal

Reputation: 6604

For External storage Use this:

File folder = new File(Environment.getExternalStorageDirectory() + "/dirName" );
        if(!folder.exists())
        {
            folder.mkdir();
            Log.i("Log", "folder created");
        }

This will create a folder with the name dirName into your sdcard . This means you get the access of the external storage by this Environment.getExternalStorageDirectory() method.

But for this you have to add the permission into your menifest file like this:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Upvotes: 1

Rushabh Patel
Rushabh Patel

Reputation: 3080

To check the sdCard is present in android device:

android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

Get the sd card's root directory:

Environment.getExternalStorageDirectory();

to store in to your phone memory into your package data folder:

String pathOfRoot = "/data/data/" + getPackageName();

Hope it will help you.

Upvotes: 1

Related Questions