當前位置: 首頁>>代碼示例>>Java>>正文


Java Environment.getDataDirectory方法代碼示例

本文整理匯總了Java中android.os.Environment.getDataDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java Environment.getDataDirectory方法的具體用法?Java Environment.getDataDirectory怎麽用?Java Environment.getDataDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.Environment的用法示例。


在下文中一共展示了Environment.getDataDirectory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractDatabase

import android.os.Environment; //導入方法依賴的package包/類
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;
}
 
開發者ID:jgilfelt,項目名稱:chuck,代碼行數:24,代碼來源:SQLiteUtils.java

示例2: checkRomSpaceEnough

import android.os.Environment; //導入方法依賴的package包/類
@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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:Utils.java

示例3: restore_Bookmarks

import android.os.Environment; //導入方法依賴的package包/類
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();
    }
}
 
開發者ID:JaeNuguid,項目名稱:Kids-Portal-Android,代碼行數:25,代碼來源:Activity_settings_data.java

示例4: backup_Bookmarks

import android.os.Environment; //導入方法依賴的package包/類
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();
    }
}
 
開發者ID:JaeNuguid,項目名稱:Kids-Portal-Android,代碼行數:25,代碼來源:Activity_settings_data.java

示例5: getRootPath

import android.os.Environment; //導入方法依賴的package包/類
/**
 * 得到SD卡根目錄.
 */
public static File getRootPath() {
    File path;
    if (sdCardIsAvailable()) {
        path = Environment.getExternalStorageDirectory(); // 取得sdcard文件路徑
    } else {
        path = Environment.getDataDirectory();
    }
    return path;
}
 
開發者ID:ChunweiDu,項目名稱:Utils,代碼行數:13,代碼來源:FileUtil.java

示例6: getRomAvailableSize

import android.os.Environment; //導入方法依賴的package包/類
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);
}
 
開發者ID:JackWHLiu,項目名稱:jackknife,代碼行數:8,代碼來源:IoUtils.java

示例7: getRomTotalSize

import android.os.Environment; //導入方法依賴的package包/類
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);
}
 
開發者ID:JackWHLiu,項目名稱:jackknife,代碼行數:8,代碼來源:IoUtils.java

示例8: backup

import android.os.Environment; //導入方法依賴的package包/類
/**
 * 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);
        }
    }
}
 
開發者ID:brolam,項目名稱:OpenHomeAnalysis,代碼行數:20,代碼來源:OhaSQLHelper.java

示例9: getAvailableInternalMemorySize

import android.os.Environment; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:13,代碼來源:MemoryCache.java

示例10: getAvailableInternalMemorySize

import android.os.Environment; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:fekracomputers,項目名稱:QuranAndroid,代碼行數:13,代碼來源:FileManager.java

示例11: getRomTotalSize

import android.os.Environment; //導入方法依賴的package包/類
/**
 * 獲得機身內存總大小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;
}
 
開發者ID:waylife,項目名稱:ViewDebugHelper,代碼行數:13,代碼來源:SdCardUtils.java

示例12: getRomTotalSize

import android.os.Environment; //導入方法依賴的package包/類
/**
    * 獲得機身內存總大小
    *
    * @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);
   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:14,代碼來源:SimpleActivity.java

示例13: getRomAvailableSize

import android.os.Environment; //導入方法依賴的package包/類
/**
    * 獲得機身可用內存
    *
    * @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);
   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:14,代碼來源:SimpleActivity.java

示例14: getUserDataDirectory

import android.os.Environment; //導入方法依賴的package包/類
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;
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:12,代碼來源:Util.java

示例15: getAvailableInternalMemorySize

import android.os.Environment; //導入方法依賴的package包/類
/**
 * 獲取手機內部剩餘存儲空間
 *
 * @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;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:13,代碼來源:RCrashHandler.java


注:本文中的android.os.Environment.getDataDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。