Android acquires body storage, built-in SD card and external TF card path

Source: Internet
Author: User

Get the body storage path (can be operated via Openfileinput,openfileoutput)
String path=environment.getdatadirectory (). GetAbsolutePath (); return/data
Get the built-in SD card path:

Public String Getstoragedir () {     if (! ( Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {     return "";     }     File dirfile=environment.getexternalstoragedirectory ();     LOG.D (TAG, Dirfile.getabsolutepath ());     return Dirfile.getabsolutepath ();    }

Back to/storage/emulated/o

To obtain an external TF card path:

Idea: Through the Mount command in Linux.

Public String Gettfdir () {string path= ""; try {InputStream ins=runtime.getruntime (). EXEC ("mount"). getInputStream (); BufferedReader reader=new BufferedReader (New InputStreamReader (INS)); String line= "", while ((Line=reader.readline ())!=null) {if (Line.contains ("SDcard")) {if (Line.contains ("Vfat") | | Line.contains ("fuse")) {String split[]=line.split ("");p ath=split[1]; LOG.D (Tag,path);}}} Reader.close (); Ins.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Finally{}return path;}
Return/storage/sdcard1 This is the path we want.

Get free space

public static long Getavailablesize (String path) {    try{        file base = new file (path);    StatFs stat = new StatFs (Base.getpath ());    Long Navailablecount = Stat.getblocksize () * ((Long) stat.getavailableblocks ());    return navailablecount;    } catch (Exception e) {    e.printstacktrace ();    }    return 0;    }
Returns the size of the bytes unit.





Android acquires body storage, built-in SD card and external TF card path

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.