当前位置: 首页>>代码示例>>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;未经允许,请勿转载。