StatFs getBlockSize - top ranked examples from Open Source projects

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

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
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
This code example shows how to use the following methods:getAvailableBlocks, getBlockCount, getBlockSize, getFreeBlocks
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
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
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
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
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
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
This code example shows how to use the following methods:getAvailableBlocks, getBlockSize
	 *            检查的路径路径 
	 * @return 在字节的可用空间 
	 */ 
	public static long getUsableSpace(File path)
	{ 
		final StatFs stats = new StatFs(path.getPath());
		return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
	} 
 
	/** 
	 * 获得外部应用程序缓存目录 
	 *  
	 * @param context 
	 *            上下文信息 
	 * @return 外部缓存目录 
	 */ 
	public static File getExternalCacheDir(Context context)
	{ 
		final String cacheDir = "/Android/data/" + context.getPackageName()
				+ "/cache/"; 
8
CodeRank

Related StatFs getBlockSize Questions & Answers:

getBlockSize Method Overview
This method was deprecated in API level 18. Use getBlockSizeLong() instead.
See Code Examples for other Android StatFs Methods: