Neetha
Neetha

Reputation: 109

Why the folder is not created in the internal storage of some android devices?

I have created a folder in the internal storage for storing files. But the issue is the folder is not created in some Android devices. The folder is created in lollipop devices but not in oreo and nougat.

The code for creating a folder in internal storage

File f1 = new File(Environment.getExternalStorageDirectory(), Constants.STORED_FOLDER);
if (!f1.exists()) {
  f1.mkdirs();
}
Log.e("check_path", "" + f1.getAbsolutePath());

Also, I have another query on how to make the folder visible in the gallery.

It is not visible in the gallery? How to solve this issue?

Upvotes: 1

Views: 1453

Answers (3)

mohamad sheikhi
mohamad sheikhi

Reputation: 394

you must add request permission before create folder. see links below : https://developer.android.com/training/permissions/requesting

Android marshmallow request permission?

Upvotes: 0

Dhiraj Choudhary
Dhiraj Choudhary

Reputation: 185

For show up your folder immediately, you need to send a broadcast

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
        Uri.parse("file://"
                + Environment.getExternalStorageDirectory())));

this code will tell the gallery app that something has been added so please rescan for media now

Upvotes: 2

Geno Chen
Geno Chen

Reputation: 5214

The folder is created in lollipop devices but not in oreo and nougat. What is the problem?

Since Android 6.0 (If my memory right), many permissions needs to be assigned dynamically (at runtime). You need to get your permission at runtime.

Is there any additional permission is needed for higher level API?

The basic permissions are WRITE_EXTERNAL_STORAGE, but you not only needs to declare it in AndroidManifest.xml, but also at runtime.

Also I have another query how to make the folder visible in gallery. It is not visible in gallery? How to solve these issue?

If you mean the photo gallery, you may need to wait for the media process to scan the whole sdcard to get your folder (which must contain some photos) added in gallery.

Upvotes: 7

Related Questions