简体   繁体   English

WhatsApp Status 储存于 Android 11 或以上

[英]WhatsApp Status Save In Android 11 or above

Please guide me how to access whatsapp status folder in android 11?请指导我如何访问 android 11 中的 whatsapp 状态文件夹? I have seen status saver apps in play store that doesn't ask for any special permission but are still able to show statuses?我在 Play 商店中看到状态保护程序应用程序不需要任何特殊许可但仍然能够显示状态? Tell me how can I access WhatsApp/Media/.Statuses folder in android 11?告诉我如何访问 android 11 中的 WhatsApp/Media/.Statuses 文件夹?

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.你可以使用 DocumentTreeIntent 来解决它,如果你让它明确地为 android 11 允许 WhatsApp 文件夹的权限,这是你如何做到这一点的方法。

     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.在使用此代码之前,您必须检查是否安装了 WhatsApp,因此首先要检查的是这里的代码。

 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?参考: 如何检查我们可以访问哪些 StorageVolume,哪些不能访问?

    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}")
}

For Fetch Whatsapp Status in Android 11 You have to Fetch this status from this path.对于 Android 中的 Fetch Whatsapp Status 11 您必须从此路径中获取此状态。 which is written below:-写在下面:-

Android->media->com.whatsapp->WhatsApp->Media->.Statues->"You can see all statues which was show by user" Android->media->com.whatsapp->WhatsApp->Media->.Statues->“你可以看到用户展示的所有雕像”

You can try this Path.你可以试试这个路径。 it may be helpful for you.这可能对你有帮助。

For Android-10 and above适用于Android-10及更高版本

File(Environment.getExternalStorageDirectory() + File.separator + "Android/media/com.whatsapp/WhatsApp/Media/.Statuses")

Below Android-10 Version Android-10以下版本

File(Environment.getExternalStorageDirectory() + File.separator + "WhatsApp/Media/.Statuses")

Please guide me how to access whatsapp status folder in android 11?请指导我如何访问 android 11 中的 whatsapp 状态文件夹? I have seen status saver apps in play store that doesn't ask for any special permission but are still able to show statuses?我在 Play 商店中看到状态保护应用程序不需要任何特殊许可但仍然能够显示状态? Tell me how can I access WhatsApp/Media/.Statuses folder in android 11?告诉我如何访问 android 11 中的 WhatsApp/Media/.Statuses 文件夹?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 android 工作室中使用 MediaStore Api 在 android 11 中获取特定文件夹,如 WhatsApp (.Status) 文件夹 - How to get specific folder like WhatsApp (.Status) folder in android 11 using MediaStore Api in android studio 通过意图打开whatsapp在Android 11中不起作用 - Opening whatsapp through intent not working in Android 11 如何访问 Whatsapp Android 11 的.Statuses 文件夹? - How to access .Statuses folder of Whatsapp Android 11? 后台位置未在 android 11 设备上方跟踪 - Background location not tracking above android 11 device 如何使用 MediaStore API 访问 Android 11 的 Whatsapp 文件夹? - How to access Whatsapp folder of Android 11 by using MediaStore API? 隐藏状态栏android时一瞥白条(如何使其像Whatsapp状态一样) - A glimpse of white bar when hiding status bar android (How to make it like Whatsapp status) 如何获取 Whatsapp 用户的状态并在我的 android 应用程序中显示? - How can i fetch Whatsapp user's status and display in my android app? 在 Android 11+ 上使状态栏完全透明 - Making status bar fully transparent on Android 11+ 无法在 Android 上以编程方式拍摄照片 11 - 意图返回已取消状态 - Cannot take a photo programmatically on Android 11 - intent returns canceled status 我在状态保护程序中工作,它在 android 11 中不起作用 - I am working in a Status saver its not working in android 11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM