Android Q (10) ask permission to get access all storage ...

文章推薦指數: 80 %
投票人數:10人

I am not talking about system root files. Root dir of mounted devices, external sd card and internal storage. – user2983041. Aug 11 '19 at 12:52. Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore AndroidQ(10)askpermissiontogetaccessallstorage.Scopedstorage AskQuestion Asked 2years,3monthsago Active 4monthsago Viewed 25ktimes 24 6 InAndroid10appsthatneedtoaccessstorageneedtoaskpermissiontoaccessaconcretepath.Butappslikefileexplorercanaskpermissionforaccesstotherootstorageandgainpermissiontoread/writetoallstorage.ThatiswhatIamtryingtodo. AccordingtoAndroidwemustuseACTION_OPEN_DOCUMENT_TREEforthis.TheproblemIhaveisthateverythingseemscorrect,butthepermissionisnotgrantedtotheapp. privatevoidaskAndroid10Perm() { Intentintent=newIntent(Intent.ACTION_OPEN_DOCUMENT_TREE); intent.addFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION |Intent.FLAG_GRANT_WRITE_URI_PERMISSION |Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION |Intent.FLAG_GRANT_PREFIX_URI_PERMISSION); startActivityForResult(intent,REQUEST_CODE_OPEN_DOCUMENT_TREE); } HeretheusercanseeAndroidfiletreeand,withmainstorageselected,clicktograntpermission."Itwillallow-appname-tohavefullaccesstoallfilescurrentlystoreunderthislocation,andanyfuturecontentstoredhere"->Allow Then: @Override protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){ super.onActivityResult(requestCode,resultCode,data); switch(requestCode){ caseREQUEST_CODE_OPEN_DOCUMENT_TREE: if(resultCode==Activity.RESULT_OK){ UritreeUri=data.getData(); inttakeFlags=data.getFlags(); takeFlags&=(Intent.FLAG_GRANT_READ_URI_PERMISSION| Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT){ Log.i("TAG","takePersistableUriPermission:"+treeUri); this.getContentResolver().takePersistableUriPermission(treeUri,takeFlags); } } } } Log: takePersistableUriPermission: content://com.android.externalstorage.documents/tree/primary%3A Thentheappwillstillnothavepermissiontoaccesstoroot. openfailed:EACCES(Permissiondenied) OfcourseIhave: Grantedbytheuser. androidandroid-10.0scoped-storage Share Improvethisquestion Follow editedApr8'20at13:24 Milk 2,14633goldbadges2626silverbadges4949bronzebadges askedAug11'19at10:36 user2983041user2983041 1,47033goldbadges1616silverbadges2727bronzebadges 6 Idon'tthinkyoucanhaverootaccessinAndroidQ – GauravMall Aug11'19at10:38 SomeappsthatItestedhavethisaccesswithscopedstorage.Forexample"Solidexplorer"app. – user2983041 Aug11'19at10:40 1 Yes,Iknow.IhadaskedasimilarquestionandCommonWaresaidtomethatthatisbecauseoftheengineersthosecompanieshave.Iknow,hisanswerwasn'tthatuseful. – GauravMall Aug11'19at10:41 whatdoyoumeanwithrootaccess? – greywolf82 Aug11'19at11:18 Accesstodevicestoragefiles.Samefilesthatshowdefaultfileexplorerpreinstalledapp.Iamnottalkingaboutsystemrootfiles.Rootdirofmounteddevices,externalsdcardandinternalstorage. – user2983041 Aug11'19at12:52  |  Show1morecomment 5Answers 5 Active Oldest Votes 41 AddlineinManifest ------------------- Share Improvethisanswer Follow editedMay13at7:16 answeredFeb20'20at9:00 D_KD_K 41455silverbadges77bronzebadges 5 Workedlikeacharm! – MohdZaid May11'20at2:26 3 Thisisonlytemporarily,seedeveloper.android.com/training/data-storage/… – dominikkv Jun9'20at13:43 Wellthatjustcostme3hoursofmylife...ThanksD_K – SimonCorcos Aug31'20at19:48 Inandroid11Itwillnotworkanymore.So,Howcanweaccessfullstorageaccessonandroid11too?anyidea? – ChiragPrajapati Jan22at2:58 YouhavetouseMediaStoreforAndroid11orabovelookoutthis:developer.android.com/training/data-storage/use-cases – D_K Jan22at7:06 Addacomment  |  11 youmustaddthislineinyourAndroidManifest.xml android:requestLegacyExternalStorage="true" Share Improvethisanswer Follow answeredJul30'20at16:46 tohidhajimoradtohidhajimorad 16811silverbadge88bronzebadges Addacomment  |  7 TheproblemwasthatIuseFileobjecttoaccessfiles,butpermissiononlyworkifweuseDocumentFileobjecttomanipulatefiles. SolvedusingDocumentFileinsteadofFile. IthasmultiplenegativepointstouseDocumentFile,suchasperformanceandthatyoudon'thaveaccesstoapachecommonslibrariesforexample,butthereisnootheroption. Share Improvethisanswer Follow answeredAug14'19at15:19 user2983041user2983041 1,47033goldbadges1616silverbadges2727bronzebadges 3 doesFile(path),file.delete(),mkdirs()notworkonandroidQ?Whatdoesscopedstoragechange? – AswinPAshok Aug14'19at18:03 3 Therearelibsforjavathatyoucancopy,cutorzipdirectoriesin"File"objectsforexample.ThislibsnotexistforDocumentFile. – user2983041 Aug15'19at18:08 FileAPIisnotavailableinandroid10forfilesinsharedstoragethatyourappdoesnotown.developer.android.com/training/data-storage/shared/… – M.RezaNasirloo Jun16at6:23 Addacomment  |  1 ItcouldbesimplerwithSimpleStorage.Youcanrequestthestoragefullaccesstotheuser: classMainActivity:AppCompatActivity(){ privatevalstorageHelper=SimpleStorageHelper(this) overridefunonCreate(savedInstanceState:Bundle?){ super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) btnRequestStorageAccess.setOnClickListener{ storageHelper.requestStorageAccess() } storageHelper.onStorageAccessGranted={requestCode,root-> //dostuff } } } ItworksonAndroid10andhigher.Noneedtoaddandroid:requestLegacyExternalStorage="true"tothemanifestfile. Share Improvethisanswer Follow answeredJul17at16:48 AnggrayudiHAnggrayudiH 14k1111goldbadges4747silverbadges7777bronzebadges Addacomment  |  0 (NOTWORKINGONANDROID11)addthisinyourmanifestfileintheapplicationsoyourapplicationwillbeasfollow: Keymapthatisdependentonthebuffer Howcananoceanofseawaterbehavelikehoneywithoutchangingthechemistry? WhatistheBiblicalbasisforthebeliefthatTrinitarianbeliefis“not”requiredforsalvation? Noviablealternativeatcharacter"" IbrokemyGstringandmyother3stringsareoutoftunetoo Projectingshadows,orevenamovie,onthemoon Whydoestheauthorassumethetemperaturetoremainconstant,inthiscase,alongtheaxialdirection? Whatdothescammersdowhentheygetaccesstosomeone'sonlinebanking? Howtoaskfriendnottoleavesoquickly,oratleastletmeknowifhedoesn'tplanonstayingverylong? Splitfilebasedonsecondcolumnvalue HowdidR3-S6makeitontoAnakin'sspaceshipwithoutarousingsuspicion? LTspicefailsatasimpletwo-resistorvoltagedivider.HowcanIfixit? Isitagoodideatomaketheactionsofmyantagonistreasonable? Whydon'tenginesshowexplicitlythatacertainmovetakestoathreefoldrepetition(insteadofjustshowing0.00)? ForeachringR,isthereablock-diagonalcanonicalformforasquarematrixoverR? Harmonicdivisornumbers CananISPblockportforwarding? HowshouldIteachlogarithmstohighschoolstudents? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?