Java Code Examples for android.os.Environment.getDataDirectory()

The following are Jave code examples for showing how to use getDataDirectory() of the android.os.Environment class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: chuck   File: SQLiteUtils.java   View Source Code Vote up 7 votes
private static String extractDatabase(Context context) {
    try {
        File external = context.getExternalFilesDir(null);
        File data = Environment.getDataDirectory();
        if (external != null && external.canWrite()) {
            String dataDBPath = "data/" + context.getPackageName() + "/databases/chuck.db";
            String extractDBPath = "chuckdb.temp";
            File dataDB = new File(data, dataDBPath);
            File extractDB = new File(external, extractDBPath);
            if (dataDB.exists()) {
                FileChannel in = new FileInputStream(dataDB).getChannel();
                FileChannel out = new FileOutputStream(extractDB).getChannel();
                out.transferFrom(in, 0, in.size());
                in.close();
                out.close();
                return extractDB.getAbsolutePath();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 2
Project: GitHub   File: Utils.java   View Source Code Vote up 6 votes
@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
    long allSize;
    long availableSize = 0;
    try {
        File data = Environment.getDataDirectory();
        StatFs sf = new StatFs(data.getPath());
        availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize();
        allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize();
    } catch (Exception e) {
        allSize = 0;
    }

    if (allSize != 0 && availableSize > limitSize) {
        return true;
    }
    return false;
}
 
Example 3
Project: Kids-Portal-Android   File: Activity_settings_data.java   View Source Code Vote up 6 votes
private void restore_Bookmarks () {
    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + "jae.KidsPortal.Browser"
                    + "//databases//" + "bookmarks_DB_v01.db";
            String backupDBPath = "//Android//" + "//data//" + "//browser.backup//" + "bookmarks_DB_v01.db";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(backupDB).getChannel();
            FileChannel dst = new FileOutputStream(currentDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();

            Snackbar.make(frameLayout, getString(R.string.toast_restore), Snackbar.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Snackbar.make(frameLayout, getString(R.string.toast_restore_not), Snackbar.LENGTH_LONG).show();
    }
}
 
Example 4
Project: Kids-Portal-Android   File: Activity_settings_data.java   View Source Code Vote up 6 votes
private void backup_Bookmarks () {
    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//" + "jae.KidsPortal.Browser"
                    + "//databases//" + "bookmarks_DB_v01.db";
            String backupDBPath = "//Android//" + "//data//" + "//browser.backup//" + "bookmarks_DB_v01.db";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            FileChannel src = new FileInputStream(currentDB).getChannel();
            FileChannel dst = new FileOutputStream(backupDB).getChannel();
            dst.transferFrom(src, 0, src.size());
            src.close();
            dst.close();

            Snackbar.make(frameLayout, getString(R.string.toast_backup), Snackbar.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Snackbar.make(frameLayout, getString(R.string.toast_backup_not), Snackbar.LENGTH_LONG).show();
    }
}
 
Example 5
Project: Utils   File: FileUtil.java   View Source Code Vote up 5 votes
/**
 * 得到SD卡根目录.
 */
public static File getRootPath() {
    File path;
    if (sdCardIsAvailable()) {
        path = Environment.getExternalStorageDirectory(); // 取得sdcard文件路径
    } else {
        path = Environment.getDataDirectory();
    }
    return path;
}
 
Example 6
Project: jackknife   File: IoUtils.java   View Source Code Vote up 5 votes
public static String getRomAvailableSize(Context context) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(context, blockSize * availableBlocks);
}
 
Example 7
Project: jackknife   File: IoUtils.java   View Source Code Vote up 5 votes
public static String getRomTotalSize(Context context) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
 
Example 8
Project: OpenHomeAnalysis   File: OhaSQLHelper.java   View Source Code Vote up 5 votes
/**
 * Realizar o backup do banco de dados compactado.
 * @param context informar um contexto válido.
 * @param backupName somente o nome do backup
 * @param iZipFile {@link br.com.brolam.library.helpers.OhaHelper.IZipFile}
 * @throws IOException
 */
public static void backup(Context context, String backupName, OhaHelper.IZipFile iZipFile) throws IOException {
    File sd = new File(Environment.getExternalStorageDirectory(),BACKUP_DIRECTORY);
    sd.mkdirs();
    File data = Environment.getDataDirectory();
    if (sd.canWrite()) {
        String dataBasePath = String.format("//data//%s//databases//%s", context.getPackageName(), DATABASE_NAME);
        File fileDataBase = new File(data, dataBasePath);
        if (fileDataBase.exists() ) {
            OhaHelper.zipFile(fileDataBase, String.format("%s/%s.zip", sd.getPath(), backupName), iZipFile);
        }
    }
}
 
Example 9
Project: AndroidBasicLibs   File: MemoryCache.java   View Source Code Vote up 5 votes
/**
 * Get available internal memory size
 *
 * @return
 */
public static long getAvailableInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}
 
Example 10
Project: QuranAndroid   File: FileManager.java   View Source Code Vote up 5 votes
/**
 * Function to get available memory size
 *
 * @return Memory size
 */
public static String getAvailableInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return formatSize(availableBlocks * blockSize);
}
 
Example 11
Project: ViewDebugHelper   File: SdCardUtils.java   View Source Code Vote up 5 votes
/**
 * 获得机身内存总大小rom
 * 
 * @return
 */
public static long getRomTotalSize() {
	File path = Environment.getDataDirectory();
	StatFs stat = new StatFs(path.getPath());
	long blockSize = stat.getBlockSize();
	long totalBlocks = stat.getBlockCount();
	return blockSize * totalBlocks;
}
 
Example 12
Project: stynico   File: SimpleActivity.java   View Source Code Vote up 5 votes
/**
    * 获得机身内存总大小
    *
    * @return
    */
   private String getRomTotalSize()
{
       File path = Environment.getDataDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long totalBlocks = stat.getBlockCount();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
   }
 
Example 13
Project: stynico   File: SimpleActivity.java   View Source Code Vote up 5 votes
/**
    * 获得机身可用内存
    *
    * @return
    */
   private String getRomAvailableSize()
{
       File path = Environment.getDataDirectory();
       StatFs stat = new StatFs(path.getPath());
       long blockSize = stat.getBlockSize();
       long availableBlocks = stat.getAvailableBlocks();
       return Formatter.formatFileSize(SimpleActivity.this, blockSize * availableBlocks);
   }
 
Example 14
Project: XPrivacy   File: Util.java   View Source Code Vote up 5 votes
public static String getUserDataDirectory(int uid) {
	// Build data directory
	String dataDir = Environment.getDataDirectory() + File.separator;
	int userId = getUserId(uid);
	if (userId == 0)
		dataDir += "data";
	else
		dataDir += "user" + File.separator + userId;
	dataDir += File.separator + Util.class.getPackage().getName();
	return dataDir;
}
 
Example 15
Project: RLibrary   File: RCrashHandler.java   View Source Code Vote up 5 votes
/**
 * 获取手机内部剩余存储空间
 *
 * @return
 */
public static long getAvailableInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}
 
Example 16
Project: Brevent   File: BreventIntentService.java   View Source Code Vote up 5 votes
private File getUserKeyFile() {
    File adbDir = new File(Environment.getDataDirectory(), ADB_DIRECTORY);
    if (adbDir.exists()) {
        return new File(adbDir, ADB_KEYS_FILE);
    } else {
        return null;
    }
}
 
Example 17
Project: BilibiliClient   File: CommonUtil.java   View Source Code Vote up 5 votes
/**
 * 获取手机内存存储可用空间
 */
public static long getPhoneAvailableSize() {

  if (!checkSdCard()) {
    File path = Environment.getDataDirectory();
    StatFs mStatFs = new StatFs(path.getPath());
    long blockSizeLong = mStatFs.getBlockSizeLong();
    long availableBlocksLong = mStatFs.getAvailableBlocksLong();
    return blockSizeLong * availableBlocksLong;
  } else
    return getSDcardAvailableSize();
}
 
Example 18
Project: BilibiliClient   File: CommonUtil.java   View Source Code Vote up 5 votes
/**
 * 获取手机内部存储总空间
 */
public static long getPhoneTotalSize() {

  if (!checkSdCard()) {
    File path = Environment.getDataDirectory();
    StatFs mStatFs = new StatFs(path.getPath());
    long blockSizeLong = mStatFs.getBlockSizeLong();
    long blockCountLong = mStatFs.getBlockCountLong();
    return blockSizeLong * blockCountLong;
  } else {
    return getSDcardTotalSize();
  }
}
 
Example 19
Project: RLibrary   File: RCrashHandler.java   View Source Code Vote up 5 votes
/**
 * 获取手机内部总的存储空间
 *
 * @return
 */
public static long getTotalInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return totalBlocks * blockSize;
}
 
Example 20
Project: XPrivacy   File: PrivacyService.java   View Source Code Vote up 4 votes
private File getDbFile() {
	return new File(Environment.getDataDirectory() + File.separator + "system" + File.separator + "xprivacy"
			+ File.separator + "xprivacy.db");
}