本文整理了Java中android.os.Environment.getDataDirectory()
方法的一些代码示例,展示了Environment.getDataDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Environment.getDataDirectory()
方法的具体详情如下:
包路径:android.os.Environment
类名称:Environment
方法名:getDataDirectory
暂无
代码示例来源:origin: zaaach/CityPicker
public DBManager(Context context) {
this.mContext = context;
DB_PATH = File.separator + "data"
+ Environment.getDataDirectory().getAbsolutePath() + File.separator
+ context.getPackageName() + File.separator + "databases" + File.separator;
copyDBFile();
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
/**
* 获取外部存储目录,一般是/sdcard/ 如果不存在,就返回/data/
*/
public static File getDataRoot() {
try {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ||
(Environment.getExternalStorageDirectory().exists() && Environment.getExternalStorageDirectory().canWrite())) {
return Environment.getExternalStorageDirectory();
} else {
return Environment.getDataDirectory();
}
} catch (Exception e) {
return null;
}
}
代码示例来源:origin: TommyLemon/APIJSON
private static CityDB openCityDB(Context context, String packageName) {
String path = "/data"
+ Environment.getDataDirectory().getAbsolutePath()
+ File.separator + packageName + File.separator
+ CityDB.CITY_DB_NAME;
File db = new File(path);
if (!db.exists()) {
try {
InputStream is = context.getAssets().open("city.db");
FileOutputStream fos = new FileOutputStream(db);
int len = -1;
byte[] buffer = new byte[1024];
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
fos.flush();
}
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
return new CityDB(context, path);
}
代码示例来源:origin: jgilfelt/chuck
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;
}
代码示例来源:origin: TommyLemon/Android-ZBLibrary
private static CityDB openCityDB(Context context, String packageName) {
String path = "/data"
+ Environment.getDataDirectory().getAbsolutePath()
+ File.separator + packageName + File.separator
+ CityDB.CITY_DB_NAME;
File db = new File(path);
if (!db.exists()) {
try {
InputStream is = context.getAssets().open("city.db");
FileOutputStream fos = new FileOutputStream(db);
int len = -1;
byte[] buffer = new byte[1024];
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
fos.flush();
}
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(0);
}
}
return new CityDB(context, path);
}
代码示例来源:origin: jeasonlzy/ImagePicker
if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
if (Utils.existSDCard()) takeImageFile = new File(Environment.getExternalStorageDirectory(), "/DCIM/camera/");
else takeImageFile = Environment.getDataDirectory();
takeImageFile = createFile(takeImageFile, "IMG_", ".jpg");
if (takeImageFile != null) {
代码示例来源:origin: joyoyao/superCleanMaster
@Override
protected Long doInBackground(Void... params) {
final CountDownLatch countDownLatch = new CountDownLatch(1);
StatFs stat = new StatFs(Environment.getDataDirectory().getAbsolutePath());
try {
mFreeStorageAndNotifyMethod.invoke(getPackageManager(),
(long) stat.getBlockCount() * (long) stat.getBlockSize(),
new IPackageDataObserver.Stub() {
@Override
public void onRemoveCompleted(String packageName, boolean succeeded)
throws RemoteException {
countDownLatch.countDown();
}
}
);
countDownLatch.await();
} catch (InvocationTargetException | InterruptedException | IllegalAccessException e) {
e.printStackTrace();
}
return mCacheSize;
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
/**
* 获取手机内部存储总空间
*/
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();
}
}
代码示例来源:origin: Rukey7/MvpApp
@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;
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
/**
* 获取手机内存存储可用空间
*/
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();
}
}
代码示例来源:origin: joyoyao/superCleanMaster
public static SDCardInfo getSystemSpaceInfo(Context context) {
File path = Environment.getDataDirectory();
// File path = context.getCacheDir().getAbsoluteFile();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
long totalSize = blockSize * totalBlocks;
long availSize = availableBlocks * blockSize;
SDCardInfo info = new SDCardInfo();
info.total = totalSize;
info.free = availSize;
return info;
}
代码示例来源:origin: ACRA/acra
/**
* Calculates the total memory of the device. This is based on an inspection of the filesystem, which in android devices is stored in RAM.
*
* @return Total number of bytes.
*/
private long getTotalInternalMemorySize() {
final File path = Environment.getDataDirectory();
final StatFs stat = new StatFs(path.getPath());
final long blockSize;
final long totalBlocks;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = stat.getBlockSizeLong();
totalBlocks = stat.getBlockCountLong();
} else {
//noinspection deprecation
blockSize = stat.getBlockSize();
//noinspection deprecation
totalBlocks = stat.getBlockCount();
}
return totalBlocks * blockSize;
}
代码示例来源:origin: ACRA/acra
/**
* Calculates the free memory of the device. This is based on an inspection of the filesystem, which in android
* devices is stored in RAM.
*
* @return Number of bytes available.
*/
private long getAvailableInternalMemorySize() {
final File path = Environment.getDataDirectory();
final StatFs stat = new StatFs(path.getPath());
final long blockSize;
final long availableBlocks;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = stat.getBlockSizeLong();
availableBlocks = stat.getAvailableBlocksLong();
} else {
//noinspection deprecation
blockSize = stat.getBlockSize();
//noinspection deprecation
availableBlocks = stat.getAvailableBlocks();
}
return availableBlocks * blockSize;
}
代码示例来源:origin: kingthy/TVRemoteIME
public static String getRootFilePath() {
if (hasSDCard()) {
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/";// filePath:/sdcard/
} else {
return Environment.getDataDirectory().getAbsolutePath() + "/data/"; // filePath:
// /data/data/
}
}
代码示例来源:origin: jingle1267/android-utils
String sourceFilePath = Environment.getDataDirectory() + "/data/"
+ context.getPackageName() + "/databases/" + databaseName;
String destFilePath = Environment.getExternalStorageDirectory()
代码示例来源:origin: smuyyh/SprintNBA
/**
* 获取Android数据目录
*
* @return
*/
public static String getDataPath() {
return Environment.getDataDirectory().getPath();
}
代码示例来源:origin: ittianyu/MobileGuard
/**
* get the rom free space
*
* @return the byte of free space
*/
public static long getRomFreeSpace() {
File directory = Environment.getDataDirectory();
return directory.getFreeSpace();
}
代码示例来源:origin: Odoo-mobile/framework
public String databaseLocalPath() {
App app = (App) mContext.getApplicationContext();
return Environment.getDataDirectory().getPath() +
"/data/" + app.getPackageName() + "/databases/" + getDatabaseName();
}
代码示例来源:origin: marzika/Snapprefs
@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesMode(Context.MODE_WORLD_READABLE);
addPreferencesFromResource(preferenceId);
File prefsFile = new File(
Environment.getDataDirectory(), "data/"
+ BaseSettings.class.getPackage().getName() + "/shared_prefs/" + BaseSettings.class.getPackage().getName()
+ "_preferences" + ".xml");
if( prefsFile.exists())
prefsFile.setReadable(true, false);
}
代码示例来源:origin: ManbangGroup/Phantom
/**
* 上报内部存储可用的磁盘空间
*/
public static void reportUsableSpaceMegabytes() {
final long usableSpaceMegabytes = Environment.getDataDirectory().getUsableSpace() / 1024 / 1024;
reportLog("usableSpace MB: " + usableSpaceMegabytes);
}
内容来源于网络,如有侵权,请联系作者删除!