How to Get Internal Memory Storage Space in Android ...

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

Every device has an internal memory where it can store files and applications. The internal memory of devices can vary anywhere between 4 GB ... Skiptocontent TutorialsPracticeDS&Algo.DSATopic-wiseDSACompany-wiseAlgorithmsAnalysisofAlgorithmsAsymptoticAnalysisWorst,AverageandBestCasesAsymptoticNotationsLittleoandlittleomeganotationsLowerandUpperBoundTheoryAnalysisofLoopsSolvingRecurrencesAmortizedAnalysisWhatdoes'SpaceComplexity'mean?Pseudo-polynomialAlgorithmsPolynomialTimeApproximationSchemeATimeComplexityQuestionSearchingAlgorithmsSortingAlgorithmsGraphAlgorithmsPatternSearchingGeometricAlgorithmsMathematicalBitwiseAlgorithmsRandomizedAlgorithmsGreedyAlgorithmsDynamicProgrammingDivideandConquerBacktrackingBranchandBoundAllAlgorithmsDataStructuresArraysLinkedListStackQueueBinaryTreeBinarySearchTreeHeapHashingGraphAdvancedDataStructureMatrixStringsAllDataStructuresInterviewCornerCompanyPreparationTopTopicsPracticeCompanyQuestionsInterviewExperiencesExperiencedInterviewsInternshipInterviewsCompetititveProgrammingDesignPatternsSystemDesignTutorialMultipleChoiceQuizzesLanguagesCC++JavaPythonC#JavaScriptjQuerySQLPHPScalaPerlGoLanguageHTMLCSSKotlinCSSubjectsMathematicsOperatingSystemDBMSComputerNetworksComputerOrganizationandArchitectureTheoryofComputationCompilerDesignDigitalLogicSoftwareEngineeringGATEGATEComputerScienceNotesLastMinuteNotesGATECSSolvedPapersGATECSOriginalPapersandOfficialKeysGATE2021DatesGATECS2021SyllabusImportantTopicsforGATECSWebTechnologiesHTMLCSSJavaScriptAngularJSReactJSNodeJSBootstrapjQueryPHPSoftwareDesignsSoftwareDesignPatternsSystemDesignTutorialSchoolLearningSchoolProgrammingMathematicsNumberSystemAlgebraTrigonometryStatisticsProbabilityGeometryMensurationCalculusMathsNotes(Class8-12)Class8NotesClass9NotesClass10NotesClass11NotesClass12NotesNCERTSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionRDSharmaSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionPhysicsNotes(Class8-11)Class8NotesClass9NotesClass10NotesClass11NotesISROCSISROCSSolvedPapersISROCSOriginalPapersandOfficialKeysISROCSSyllabusforScientist/EngineerExamUGCNETCSUGCNETCSNotesPaperIIUGCNETCSNotesPaperIIIUGCNETCSSolvedPapersStudentCampusAmbassadorProgramSchoolAmbassadorProgramProjectGeekoftheMonthCampusGeekoftheMonthPlacementCourseCompetititveProgrammingTestimonialsGeekontheTopCareersInternshipJobsApplyforJobsPostaJobCourses ComewritearticlesforusandgetfeaturedLearnandcodewiththebestindustryexpertsGetaccesstoad-freecontent,doubtassistanceandmore!ComeandfindyourdreamjobwithusGeeksDigestQuizzesGeeksCampusGblogArticlesIDECampusMantri HomeSavedVideosCoursesGBlogPuzzlesWhat'sNew? ChangeLanguage DataStructuresAlgorithmsInterviewPreparationTopic-wisePracticeC++JavaPythonCompetitiveProgrammingMachineLearningWebDevelopmentPuzzlesProjectIdeasSchoolLearning RelatedArticles ▲RelatedArticlesBottomNavigationBarinAndroidHowtoChangetheBackgroundColorofButtoninAndroidusingColorStateList?AndroidTutorialAndroidArchitectureServicesinAndroidwithExampleMVVM(ModelViewViewModel)ArchitecturePatterninAndroidHowtoAddandCustomizeBackButtonofActionBarinAndroid?AndroidProjects-FromBasictoAdvancedLevelHowtochangethecolorofActionBarinanAndroidApp?HowtoInstallandSetupAndroidStudioonWindows?ContentProvidersinAndroidwithExampleKotlinAndroidTutorialCardViewinAndroidWithExampleHowtoPushNotificationinAndroidusingFirebaseCloudMessaging?HowtoChangetheColorofStatusBarinanAndroidApp?ImageSliderinAndroidusingViewPagerHowtoCreateaQuizAppInAndroid?HowtoUpdateGradleinAndroidStudio?AndroidProjectfolderStructureAndroid|build.gradleBroadcastReceiverinAndroidWithExampleFix"UnabletolocateadbwithinSDK"inAndroidStudioHowtoUploadProjectonGitHubfromAndroidStudio?BestWaytoBecomeAndroidDeveloper–ACompleteRoadmapFirebaseAuthenticationwithPhoneNumberOTPinAndroidHowtoFix“FailedtoinstallthefollowingAndroidSDKpackagesassomelicenseshavenotbeenaccepted”ErrorinAndroidStudio?AssetsFolderinAndroidStudioExternalStorageinAndroidwithExampleHowtoAddaFloatingActionButtontoBottomNavigationBarinAndroid?NavigationDrawerinAndroidTableofContentsBottomNavigationBarinAndroidHowtoChangetheBackgroundColorofButtoninAndroidusingColorStateList?AndroidTutorialAndroidArchitectureServicesinAndroidwithExampleMVVM(ModelViewViewModel)ArchitecturePatterninAndroidHowtoAddandCustomizeBackButtonofActionBarinAndroid?AndroidProjects-FromBasictoAdvancedLevelHowtochangethecolorofActionBarinanAndroidApp?HowtoInstallandSetupAndroidStudioonWindows?ContentProvidersinAndroidwithExampleKotlinAndroidTutorialCardViewinAndroidWithExampleHowtoPushNotificationinAndroidusingFirebaseCloudMessaging?HowtoChangetheColorofStatusBarinanAndroidApp?ImageSliderinAndroidusingViewPagerHowtoCreateaQuizAppInAndroid?HowtoUpdateGradleinAndroidStudio?AndroidProjectfolderStructureAndroid|build.gradleBroadcastReceiverinAndroidWithExampleFix"UnabletolocateadbwithinSDK"inAndroidStudioHowtoUploadProjectonGitHubfromAndroidStudio?BestWaytoBecomeAndroidDeveloper–ACompleteRoadmapFirebaseAuthenticationwithPhoneNumberOTPinAndroidHowtoFix“FailedtoinstallthefollowingAndroidSDKpackagesassomelicenseshavenotbeenaccepted”ErrorinAndroidStudio?AssetsFolderinAndroidStudioExternalStorageinAndroidwithExampleHowtoAddaFloatingActionButtontoBottomNavigationBarinAndroid?NavigationDrawerinAndroidSaveArticle ImproveArticle SaveArticle LikeArticle HowtoGetInternalMemoryStorageSpaceinAndroidProgrammatically?LastUpdated: 27Sep,2021Everydevicehasaninternalmemorywhereitcanstorefilesandapplications.Theinternalmemoryofdevicescanvaryanywherebetween4GBto512GB.Asinternalmemorygetsfilledupwithastackoffilesandapplications,theavailablespacedecreases.Developers,tosaveinternalmemory,designfewapplicationssothattheystaycompressedwhennotrunningandexpandoncetriggered.Now,ifavailablespaceislessthantheexpandedversionofatriggeredapplication,thedevicemighthangup,ortheapplicationmightneveropeninthedevice.Wantamorefast-paced&competitiveenvironmenttolearnthefundamentalsofAndroid?Clickheretoheadtoaguideuniquelycuratedbyourexpertswiththeaimtomakeyouindustryreadyinnotime!So,torunsuchapplicationsefficiently,itisnecessarytokeeptrackofinternalmemory.Inthisarticle,wewillshowyouhowyoucouldgetreal-timeinformationaboutinternalmemory.StepbyStepImplementationStep1:CreateaNewProjectinAndroidStudioTocreateanewprojectinAndroidStudiopleaserefertoHowtoCreate/StartaNewProjectinAndroidStudio.WedemonstratedtheapplicationinKotlin,somakesureyouselectKotlinastheprimarylanguagewhilecreatingaNewProject.Step2:Workingwiththeactivity_main.xmlfileNavigatetotheapp>res>layout>activity_main.xmlandaddthebelowcodetothatfile.Belowisthecodefortheactivity_main.xmlfile.AddaTextViewinthelayouttodisplaytheinfo.XML        Step3:WorkingwiththeMainActivity.ktfileGototheMainActivity.ktfileandrefertothefollowingcode.BelowisthecodefortheMainActivity.ktfile.Commentsareaddedinsidethecodetounderstandthecodeinmoredetail.Kotlinimportandroid.os.Buildimportandroid.os.Bundleimportandroid.os.Environmentimportandroid.os.StatFsimportandroid.widget.TextViewimportandroidx.annotation.RequiresApiimportandroidx.appcompat.app.AppCompatActivityimportjava.io.File  classMainActivity:AppCompatActivity(){    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR2)    overridefunonCreate(savedInstanceState:Bundle?){        super.onCreate(savedInstanceState)        setContentView(R.layout.activity_main)          //TextViewtoshowinformation        valmTextView=findViewById(R.id.text_view)            //Fetchinginternalmemoryinformation        valiPath:File=Environment.getDataDirectory()        valiStat=StatFs(iPath.path)        valiBlockSize=iStat.blockSizeLong        valiAvailableBlocks=iStat.availableBlocksLong        valiTotalBlocks=iStat.blockCountLong        valiAvailableSpace=formatSize(iAvailableBlocks*iBlockSize)        valiTotalSpace=formatSize(iTotalBlocks*iBlockSize)          //Displayingthefetchedinfo        mTextView.text="InternalAvailable:$iAvailableSpace\nInternalTotal:$iTotalSpace"      }      //FunctiontoconvertbytertoKBandMB    privatefunformatSize(size:Long):String?{        varsize=size        varsuffix:String?=null        if(size>=1024){            suffix="KB"            size/=1024            if(size>=1024){                suffix="MB"                size/=1024            }        }        valresultBuffer=StringBuilder(java.lang.Long.toString(size))        varcommaOffset=resultBuffer.length-3        while(commaOffset>0){            resultBuffer.insert(commaOffset,',')            commaOffset-=3        }        if(suffix!=null)resultBuffer.append(suffix)        returnresultBuffer.toString()    }}Output:Youcanseethatwhentheapplicationopens,theinformationregardingtheinternalmemoryisdisplayed.MyPersonalNotes arrow_drop_upSave LikePreviousClassificationofColloidsNext Is3asquareroot?RecommendedArticlesPage:01,Sep2126,Oct2029,Jun2124,Sep2122,May2024,Feb2110,Oct2010,Oct2007,Oct2010,Oct2009,Oct2010,Oct2010,Oct2009,Oct2010,Oct2010,Oct2010,Oct2009,Oct2011,Oct2010,Oct2010,Oct2011,Oct2010,Oct2008,Oct20ArticleContributedBy:aashaypawar@aashaypawarVotefordifficultyEasy Normal Medium Hard ExpertArticleTags:AndroidKotlinPracticeTags:AndroidReportIssueWritingcodeincomment? Pleaseuseide.geeksforgeeks.org, generatelinkandsharethelinkhere. LoadCommentsWhat'sNewViewDetailsViewDetailsViewDetailsMostpopularinAndroidHowtoCreateandAddDatatoSQLiteDatabaseinAndroid?AndroidRecyclerViewinKotlinHowtoViewandLocateSQLiteDatabaseinAndroidStudio?HowtoRetrieveDatafromtheFirebaseRealtimeDatabaseinAndroid?Howtofix"AndroidStudiodoesn'tseedevice"inAndroidStudio?MostvisitedinKotlinAndroidRecyclerViewinKotlinKotlinArrayAndroidUILayoutsHowtoConvertKotlinCodetoJavaCodeinAndroidStudio?MVP(ModelViewPresenter)ArchitecturePatterninAndroidwithExample× Weusecookiestoensureyouhavethebestbrowsingexperienceonourwebsite.Byusingoursite,you acknowledgethatyouhavereadandunderstoodour CookiePolicy& PrivacyPolicy GotIt!



請為這篇文章評分?