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();
9
CodeRank
Experience pair programming with AI  Get Codota for Java
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);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
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;
	} 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
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 = ");
8
CodeRank
Experience pair programming with AI  Get Codota for Java
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);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAvailableBlocks, getBlockSize
        if (!dir.isDirectory() || !dir.canWrite()) {
            return UNAVAILABLE;
        } 
 
        try { 
            StatFs stat = new StatFs(DIRECTORY);
            return stat.getAvailableBlocks() * (long) stat.getBlockSize();
        } catch (Exception e) {
            Log.i(TAG, "Fail to access external storage", e);
        } 
        return UNKNOWN_SIZE;
    } 
 
    /** 
     * OSX requires plugged-in USB storage to have path /DCIM/NNNAAAAA to be 
     * imported. This is a temporary fix for bug#1655552. 
     */ 
    public static void ensureOSXCompatible() { 
        File nnnAAAAA = new File(DCIM, "100ANDRO");
        if (!(nnnAAAAA.exists() || nnnAAAAA.mkdirs())) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java
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);
	} 
 
	/** 
	 * 新建目录 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAvailableBlocks, getBlockCount
		long availableBlocks = stat.getAvailableBlocks();
		return availableBlocks*blockSize;
	} 
	 
	public static int getAvailablePhonePer() { 
		StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
        int availablePercent = stat.getAvailableBlocks() * 100 / stat.getBlockCount();
        return availablePercent;
	} 
	 
	public static void createDirIfNotExist(String _path) {
		File f = new File(_path);
		try { 
			if (f.exists()) {
				//directory already exists 
			} else { 
				if (f.mkdirs()) {
					Log.v(TAG, "createDirIfNotExist created " + _path);
				} else { 
					Log.v(TAG, "createDirIfNotExist failed to create " + _path);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getBlockCount, getBlockSize
        return availableBlocks * blockSize;
    } 
 
    public long getTotalInternalMemorySize() { 
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        return totalBlocks * blockSize;
    } 
 
    void recoltInformations(Context context) {
        PackageManager pm = context.getPackageManager();
        try { 
            PackageInfo pi;
            // Version 
            pi = pm.getPackageInfo(context.getPackageName(), 0);
            VersionName = pi.versionName;
            // Package name 
            PackageName = pi.packageName;
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAvailableBlocks, getBlockSize
        if (!dir.isDirectory() || !dir.canWrite()) {
            return UNAVAILABLE;
        } 
 
        try { 
            StatFs stat = new StatFs(generateDirectory());
            return stat.getAvailableBlocks() * (long) stat.getBlockSize();
        } catch (Exception e) {
            Log.i(TAG, "Fail to access external storage", e);
        } 
        return UNKNOWN_SIZE;
    } 
 
    /** 
     * OSX requires plugged-in USB storage to have path /DCIM/NNNAAAAA to be 
     * imported. This is a temporary fix for bug#1655552. 
     */ 
    public void ensureOSXCompatible() { 
        File nnnAAAAA = new File(generateDCIM(), "100ANDRO");
        if (!(nnnAAAAA.exists() || nnnAAAAA.mkdirs())) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android StatFs Questions & Answers:

See Code Examples for Android StatFs Methods: