日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢(xún)客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

本文介紹了在Android 11或更高版本中保存WhatsApp狀態(tài)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

請(qǐng)指導(dǎo)我如何訪問(wèn)Android 11中的WhatsApp Status文件夾?
我在Play商店中看到過(guò)狀態(tài)保護(hù)應(yīng)用程序,它們不需要任何特殊許可,但仍然可以顯示狀態(tài)?
告訴我如何訪問(wèn)Android 11中的WhatsApp/Media/.Status文件夾?

推薦答案

如果您將DocumentTreeIntent設(shè)置為顯式允許對(duì)Android 11的WhatsApp文件夾的權(quán)限,則可以使用DocumentTreeIntent解決此問(wèn)題。以下是您可以執(zhí)行此操作的方法。

     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;
    }

在使用此代碼之前,您必須檢查是否安裝了WhatsApp,因此第一個(gè)檢查是檢查,這是該代碼。

 try {

        context.getPackageManager().getPackageInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
       
     }

授予權(quán)限后,您必須通過(guò)此代碼檢索文件

 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();

您可以從下面的代碼中獲取有關(guān)文檔樹(shù)意圖的更多詳細(xì)信息,這只是為了便于理解

引用: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}")
}

這篇關(guān)于在Android 11或更高版本中保存WhatsApp狀態(tài)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,

分享到:
標(biāo)簽:Android Whatsapp 保存 或更高 版本 狀態(tài)
用戶(hù)無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定