Private folder on Internal/external storage on android - Stack ...
文章推薦指數: 80 %
If you want to save files that are private to your app, you can acquire the appropriate directory by calling getExternalFilesDir() and passing ... 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 PrivatefolderonInternal/externalstorageonandroid AskQuestion Asked 6years,1monthago Active 6years,1monthago Viewed 10ktimes 6 2 Iwanttocreateaprivatefolderformyappdata.Thisfolderhastobedeletedautomaticallywhentheappisremovedfromthedevice.Accordingtohttp://developer.android.com/training/basics/data-storage/files.html,Ihavetocreateaprivatefolder.HowcanIachievethis.Mycodebelow.Folderisnotdeletedwhentheappisremoved. publicstaticStringgetAppFilePath(Contextcontext){ Stringpath=""; if(Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)){ path=Environment.getExternalStorageDirectory() .getAbsolutePath(); path+="/myFolder"; }else{ ContextWrapperc=newContextWrapper(context); path=c.getFilesDir().getPath(); } Fileret=newFile(path); if(!ret.exists()){ ret.mkdirs(); } returnpath; } androidfile Share Follow askedOct20'15at9:01 patspats 1,14522goldbadges1818silverbadges3636bronzebadges Addacomment | 2Answers 2 Active Oldest Votes 9 youaredoingitwrong. fromthedocumentationyoupointed: Ifyouwanttosavefilesthatareprivatetoyourapp,youcan acquiretheappropriatedirectorybycallinggetExternalFilesDir() andpassingitanameindicatingthetypeofdirectoryyou'dlike. Eachdirectorycreatedthiswayisaddedtoaparentdirectorythat encapsulatesallyourapp'sexternalstoragefiles,whichthesystem deleteswhentheuseruninstallsyourapp. Forexample,here'samethodyoucanusetocreateadirectoryforan individualphotoalbum: publicFilegetAlbumStorageDir(Contextcontext,StringalbumName){ //Getthedirectoryfortheapp'sprivatepicturesdirectory. Filefile=newFile(context.getExternalFilesDir( Environment.DIRECTORY_PICTURES),albumName); if(!file.mkdirs()){ Log.e(LOG_TAG,"Directorynotcreated"); } returnfile; } Ifnoneofthepre-definedsub-directorynamessuityourfiles,you caninsteadcallgetExternalFilesDir()andpassnull.Thisreturnsthe rootdirectoryforyourapp'sprivatedirectoryontheexternal storage. RememberthatgetExternalFilesDir()createsadirectoryinsideadirectorythatisdeletedwhentheuseruninstallsyourapp.Ifthe filesyou'resavingshouldremainavailableaftertheuseruninstalls yourapp—suchaswhenyourappisacameraandtheuserwillwantto keepthephotos—youshouldinsteaduse getExternalStoragePublicDirectory(). sobasicallyyouneedtousegetExternalFilesDirfunctionintheexampleabovetogetitdeletedwhenappinuninstalled. accordingtodocumentationforgetExternalFilesDir() Parameters typeThetypeoffilesdirectorytoreturn.Maybenullfor therootofthefilesdirectoryoroneofthefollowingconstantsfor asubdirectory:DIRECTORY_MUSIC,DIRECTORY_PODCASTS, DIRECTORY_RINGTONES,DIRECTORY_ALARMS,DIRECTORY_NOTIFICATIONS, DIRECTORY_PICTURES,orDIRECTORY_MOVIES. soapartfrompredefinedtypesyoucanusenullforrootofthedirectory. Share Follow editedOct20'15at10:23 answeredOct20'15at9:12 RahulTiwariRahulTiwari 6,10822goldbadges4343silverbadges6767bronzebadges 4 Yes,Ireadthatpartinthereference,butwhatEnvironment.variableshouldIuse?Ihavedocumentsandcoupleofimages. – pats Oct20'15at10:06 checkupdatedanswer,youcanusenullforrootasthereisnosubdirectoryfordocuments.forpicturesuseDIRECTORY_PICTURES – RahulTiwari Oct20'15at10:24 1 Whydoesthejavadocsaythefollowing:"Thereisnosecurityenforcedwiththesefiles.Forexample,anyapplicationholdingWRITE_EXTERNAL_STORAGEcanwritetothesefiles."Itseemslikeanyappwithstorageaccessthatknowsmypackagenamecouldaccessthesefiles? – laim2003 Apr14'19at17:27 1 @laim2003usegetFilesDir()insteadifsecurityoffilesisyourconcern – RahulTiwari Apr15'19at10:37 Addacomment | -1 Insimplewordsyoucannot. ItisnotpossibleasyoucannothandleeventafteruninstallingtheApp. Share Follow answeredOct20'15at9:13 DroidAksDroidAks 32722silverbadges99bronzebadges Addacomment | YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedandroidfileoraskyourownquestion. TheOverflowBlog Whoownsthisoutage?BuildingintelligentescalationchainsformodernSRE Podcast395:Whoisbuildingcloudsfortheindependentdeveloper? FeaturedonMeta Nowlive:Afullyresponsiveprofile Reducingtheweightofourfooter TwoBornottwoB-Farewell,BoltClockandBhargav! Visitchat Related 2088 IsthereawaytorunPythononAndroid? 2031 HowtolazyloadimagesinListViewinAndroid 4135 Howdoyouclose/hidetheAndroidsoftkeyboardprogrammatically? 3057 HowtostopEditTextfromgainingfocusatActivitystartupinAndroid 1960 "Debugcertificateexpired"errorinEclipseAndroidplugins 2942 IsthereauniqueAndroiddeviceID? 2137 Whatis'Context'onAndroid? 1475 DownloadasinglefolderordirectoryfromaGitHubrepo 3843 ProperusecasesforAndroidUserManager.isUserAGoat()? HotNetworkQuestions SQLexpressionworksinDBManagerbutnotinQueryBuilder/Filter,returns"OGR[3]error1:Undefinedfunction"error Adjustbrakestoavoiddeflatingtireforremoval compassandstraightedgeinacientGreek? Istherearootwordfor-scendo? Whydoweneedinsulationmaterialbetweentwowalls? Whydopeoplecaresomuchabout'linearresponsetheory'? InthesecondDeathlyHallowsfilm,didHarrychangeclotheswhileSnapeandMcGonagallwerefighting? Convertprefixtoinfix CanImakeahelixwith4strands? Whyisthecurrententeringaconductorthesameastheoneexitingit? IsLisztreallypronouncedliketheEnglishword"list"? Howtorepresentbeamsbrokenwithrestsinlilypond GraphsfromthepointofviewofRiemannsurfaces Foraspacecraftorbitingaplanet,orbitalspeedisinverselyproportionaltoorbitradius.Butspeedmustbeincreasedtoincreaseorbitradius? Datastructurethatsupportsinsertionandfastrandomelementlookup HowcanIgettrue1"thickoakboards? ConvertRegextoMask Where(inGermany)isthelandscapebehindthisnewsreader,withagazeboonasmall,lushsteephillsurroundedbyhigher,broaderforestedhills? LTspicefailsatasimpletwo-resistorvoltagedivider.HowcanIfixit? WhyarelegaldecisionsintheUSsopoliticized? ForeachringR,isthereablock-diagonalcanonicalformforasquarematrixoverR? Couldsiliconbasedlifeformseatcarbonbasedfood Islookingforplaintextstringsonanencrypteddiskagoodtest? Oxidationnumberofmethyleneblue morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1Google: This Android PIN-protected 'Safe' folder lets you lock ...
- 2How to hide apps, photos, and files on Android devices
Secure Folder is one of the best features available on Samsung phones and allows you to hide phot...
- 3How do I access private folder on Android? - OS Today
How do I find hidden apps on Android?
- 4How to Hide Your Private Photos on Android - MakeUseOf
... your Android gallery? Check out these methods to keep your secret photos safe. ... To hide ph...
- 5How do you make a private folder on Android? - OS Today
What is the best hidden text app?