Please guide me how to access whatsapp status folder in android 11? I have seen status saver apps in play store that doesn't ask for any special permission but are still able to show statuses? Tell me how can I access WhatsApp/Media/.Statuses folder in android 11?
-
honestly what's wrong with this question that It deservs a downvote – Jun 02 '21 at 03:08
-
Can you please paste the link of app ? As far as I know it is not possible. – Smeet Jun 06 '21 at 12:20
-
how do you know it is not possible? Does android 11 limit access to android/media folder? – Jun 06 '21 at 14:31
-
Yes correct, without permission any app can not access the media files from external storage. If you can give play store link then we can find exactly how it is working and I can more comment on it. – Smeet Jun 07 '21 at 05:02
-
Similar question https://stackoverflow.com/questions/70127116/access-hidden-folders-in-flutter-for-android-11 You can check in question that user asking for same thing in visual form – Ankit Parmar Nov 27 '21 at 17:11
4 Answers
You can solve it using the DocumentTreeIntent if you make it allow permission for the WhatsApp folder explicitly for android 11 here is how you can do that.
if (Constants.isPackageInstalled(getActivity(), "com.whatsapp")) {
Intent intent;
StorageManager sm = (StorageManager) getActivity().getSystemService(STORAGE_SERVICE);
String statusDir = getWhatsupFolder();
String str = "android.provider.extra.INITIAL_URI";
if (Build.VERSION.SDK_INT >= 29) {
intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent();
String scheme = ((Uri) intent.getParcelableExtra(str)).toString().replace("/root/", "/document/");
String stringBuilder = scheme +
"%3A" +
statusDir;
intent.putExtra(str, Uri.parse(stringBuilder));
} else {
intent = new Intent("android.intent.action.OPEN_DOCUMENT_TREE");
intent.putExtra(str, Uri.parse(statusDir));
}
intent.addFlags(2);
intent.addFlags(1);
intent.addFlags(128);
intent.addFlags(64);
startActivityForResult(intent, REQUEST_ACTION_OPEN_DOCUMENT_TREE);
return;
}
before using this code you must check if WhatsApp is installed or not so the first check is for that here is the code for that.
try {
context.getPackageManager().getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
after granting permission you must retrieve files via this code
private DocumentFile[] getFromSdcard() {
DocumentFile fromTreeUri = DocumentFile.fromTreeUri(requireContext().getApplicationContext(), Uri.parse(namedataprefs));
if (fromTreeUri != null && fromTreeUri.exists() && fromTreeUri.isDirectory() && fromTreeUri.canRead() && fromTreeUri.canWrite()) {
return fromTreeUri.listFiles();
}
return null;
}
DocumentFile[] allFiles = getFromSdcard();
//to get signal file path
String path = allFiles[0].getUri().toString();
you can get further details about document tree intent from the below code its just for understanding purposes
Ref : How to check which StorageVolume we have access to, and which we don't?
requestAccessButton.setOnClickListener {
storageVolumes = storageManager.storageVolumes
val primaryVolume = storageManager.primaryStorageVolume
val intent = primaryVolume.createOpenDocumentTreeIntent()
startActivityForResult(intent, 1)
}
}
private fun checkAccessToStorageVolumes() {
val storageVolumePathsWeHaveAccessTo = HashSet<String>()
val persistedUriPermissions = contentResolver.persistedUriPermissions
persistedUriPermissions.forEach {
storageVolumePathsWeHaveAccessTo.add(it.uri.toString())
}
val storageManager = getSystemService(Context.STORAGE_SERVICE) as StorageManager
val storageVolumes = storageManager.storageVolumes
for (storageVolume in storageVolumes) {
val uuid = if (storageVolume.isPrimary) {
// Primary storage doesn't get a UUID here.
"primary"
} else {
storageVolume.uuid
}
val volumeUri = uuid?.let { buildVolumeUriFromUuid(it) }
when {
uuid == null ->
Log.d("AppLog", "UUID is null for ${storageVolume.getDescription(this)}!")
storageVolumePathsWeHaveAccessTo.contains(volumeUri) ->
Log.d("AppLog", "Have access to $uuid")
else -> Log.d("AppLog", "Don't have access to $uuid")
}
}
}
private fun buildVolumeUriFromUuid(uuid: String): String {
return DocumentsContract.buildTreeDocumentUri(
"com.android.externalstorage.documents",
"$uuid:"
).toString()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
Log.d("AppLog", "resultCode:$resultCode")
val uri = data?.data ?: return
val takeFlags =
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
contentResolver.takePersistableUriPermission(uri, takeFlags)
Log.d("AppLog", "granted uri: ${uri.path}")
}

- 126
- 3
- 11

- 1,307
- 13
- 22
-
Thanks for the answer! but what is Uri.parse(namedataprefs) in the code? – Haris Abdullah Mar 02 '22 at 06:05
-
sir this saves the location in sharedpresf so it can be retrieved later – Syed Usama Ahmad Mar 02 '22 at 07:39
For Fetch Whatsapp Status in Android 11 You have to Fetch this status from this path. which is written below:-
Android->media->com.whatsapp->WhatsApp->Media->.Statues->"You can see all statues which was show by user"

- 11
- 1
You can try this Path. it may be helpful for you.
For Android-10
and above
File(Environment.getExternalStorageDirectory() + File.separator + "Android/media/com.whatsapp/WhatsApp/Media/.Statuses")
Below Android-10
Version
File(Environment.getExternalStorageDirectory() + File.separator + "WhatsApp/Media/.Statuses")

- 418
- 2
- 10
-
`Environment.getExternalStorageDirectory()` is deprecated in new Androids and `File` API cannot be used directly anymore on new Androids without very special permissions or user selecting it – cmak Oct 19 '22 at 01:31
Just follow the simple steps:-
private fun getFolderPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val sm =
requireContext().applicationContext.getSystemService(AppCompatActivity.STORAGE_SERVICE) as StorageManager
val intent = sm.primaryStorageVolume.createOpenDocumentTreeIntent()
val starDir = "Android%2Fmedia%2Fcom.whatsapp%2FWhatsApp%2FMedia%2F.Statuses"
var uri = intent.getParcelableExtra<Uri>("android.provider.extra.INITIAL_URI")
var scheme = uri.toString()
scheme=scheme.replace("/root/","/document/")
scheme += "%3A$starDir"
uri = Uri.parse(scheme)
intent.putExtra("android.provider.extra.INITIAL_URI", uri)
startActivityForResult(intent, 1234)
}
checkPermissions(0)
}
private fun checkPermissions(type: Int): Boolean {
var result: Int
val listPermissionNeeded: MutableList<String> = ArrayList()
for (p in permissions) {
result = ContextCompat.checkSelfPermission(requireContext(), p)
if (result != PackageManager.PERMISSION_GRANTED) {
listPermissionNeeded.add(p)
}
}
if (listPermissionNeeded.isNotEmpty()) {
ActivityCompat.requestPermissions(
(activity as Activity?)!!,
listPermissionNeeded.toTypedArray(),
type
)
return false
} else {
getData()
}
return true
}
private fun getData() {
var targetPath =
Environment.getExternalStorageDirectory().absolutePath + "/WhatsApp/Media/.Statuses"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
targetPath =
Environment.getExternalStorageDirectory().absolutePath + "/Android/media/com.whatsapp/WhatsApp/Media/.Statuses"
}
val targetDirector = File(targetPath)
val allFiles = targetDirector.listFiles()
try {
list.clear()
for (file in allFiles) {
if (!file.name.endsWith(".nomedia")) {
if (file.name.endsWith(".jpg")) {
list.add(StatusModel(file.name, file.path))
}
}
}
setUpRecyclerView(list)
} catch (e: Exception) {
Toast.makeText(requireContext(), "" + e.message, Toast.LENGTH_SHORT).show()
}
}

- 31
- 3