本文整理汇总了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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}