Android StatFs - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android StatFs class.

This code example shows how to use the following methods: getAvailableBlocks, getBlockSize
		String status = Environment.getExternalStorageState();
		long freeSpace = 0;
		if (status.equals(Environment.MEDIA_MOUNTED)) {
			try { 
				File path = Environment.getExternalStorageDirectory();
				StatFs stat = new StatFs(path.getPath());
				long blockSize = stat.getBlockSize();
				long availableBlocks = stat.getAvailableBlocks();
				freeSpace = availableBlocks*blockSize/1024;
			} catch (Exception e) {e.printStackTrace(); }
		} else { return -1; } 
		return (freeSpace);
	}	 
	 
	protected boolean createDirectory(String directoryName){
		boolean status;
		if ((testSaveLocationExists())&&(!directoryName.equals(""))){
			File path = Environment.getExternalStorageDirectory();
            File newPath = constructFilePaths(path.toString(), directoryName);
			status = newPath.mkdir();
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getBlockCount, getBlockSize
     * 
     * @return Total number of bytes. 
     */ 
    public static long getTotalInternalMemorySize() { 
        final File path = Environment.getDataDirectory();
        final StatFs stat = new StatFs(path.getPath());
        final long blockSize = stat.getBlockSize();
        final long totalBlocks = stat.getBlockCount();
        return totalBlocks * blockSize;
    } 
 
    /** 
     * Returns the DeviceId according to the TelephonyManager. 
     * 
     * @param context   Context for the application being reported. 
     * @return Returns the DeviceId according to the TelephonyManager or null if there is no TelephonyManager. 
     */ 
    public static String getDeviceId(Context context) {
        try { 
            final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getAvailableBlocks, getBlockCount, getBlockSize, getFreeBlocks
	} 
	 
	 
	 
	public static long getAvailableSDSpace() { 
		 StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());        
		 long blockSize = statFs.getBlockSize();
		 long totalSize = statFs.getBlockCount()*blockSize;
		 long availableSize = statFs.getAvailableBlocks()*blockSize;
		 long freeSize = statFs.getFreeBlocks()*blockSize;
		 return availableSize;
	} 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getAvailableBlocks, getBlockCount, getBlockSize
        // add configurable (through args) performance test parameters. 
    } 
 
    private void reportFreeSpace(File path, String name, PrintWriter pw) {
        try { 
            StatFs statfs = new StatFs(path.getPath());
            long bsize = statfs.getBlockSize();
            long avail = statfs.getAvailableBlocks();
            long total = statfs.getBlockCount();
            if (bsize <= 0 || total <= 0) {
                throw new IllegalArgumentException(
                        "Invalid stat: bsize=" + bsize + " avail=" + avail + " total=" + total);
            } 
 
            pw.print(name);
            pw.print("-Free: ");
            pw.print(avail * bsize / 1024);
            pw.print("K / ");
            pw.print(total * bsize / 1024);
            pw.print("K total = ");
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getAvailableBlocks, getBlockSize
        File savePath = Environment.getExternalStorageDirectory();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
            return savePath.getUsableSpace();
 
        } else { 
            StatFs stats = new StatFs(savePath.getAbsolutePath());
            return stats.getAvailableBlocks() * stats.getBlockSize();
        } 
 
    } 
 
    // to ensure we will not add the slash twice between filename and 
    // folder-name 
    private static String getFileName(String filepath) {
        if (filepath != null && !"".equals(filepath)) {
            int psi = filepath.lastIndexOf('/');
            String filename = filepath;
            if (psi > -1) {
                filename = filepath.substring(psi + 1, filepath.length());
                Log.d(LOG_TAG, "extracted filename :" + filename);
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android StatFs Questions & Answers:

See Code Examples for Android StatFs Methods: