List of usage examples for android.os Environment getDataDirectory
public static File getDataDirectory()
From source file:com.colorchen.qbase.utils.FileUtil.java
/** * SD?.//from ww w. j av a 2 s . co m */ public static File getRootPath() { File path = null; if (sdCardIsAvailable()) { path = Environment.getExternalStorageDirectory(); // ?sdcard } else { path = Environment.getDataDirectory(); } return path; }
From source file:com.fallahpoor.infocenter.fragments.StorageFragment.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private String getInternalFree() { long size;//from w w w. j av a2 s.c o m StatFs internalStatFs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); if (mIsApiAtLeast18) { size = internalStatFs.getAvailableBytes(); } else { size = (long) internalStatFs.getAvailableBlocks() * (long) internalStatFs.getBlockSize(); } return Utils.getFormattedSize(size); }
From source file:com.twentyoneechoes.borges.util.Utils.java
public static void backupDatabase(Context ctx) { try {//from w w w. j av a 2 s . c o m File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "//data//" + ctx.getApplicationContext().getPackageName() + "//databases//borges.db"; String backupDBPath = "borges.db"; File currentDB = new File(data, currentDBPath); File backupDB = new File(sd, backupDBPath); if (currentDB.exists()) { FileChannel src = new FileInputStream(currentDB).getChannel(); FileChannel dst = new FileOutputStream(backupDB).getChannel(); dst.transferFrom(src, 0, src.size()); src.close(); dst.close(); } } } catch (Exception e) { Log.i(Utils.class.getSimpleName(), "Unable to backup database"); } }
From source file:com.colorchen.qbase.utils.FileUtil.java
/** * ?SD?Data//from w ww .jav a 2s . c o m * * @return SD?Data */ public static String getDataPath() { if (!isSDCardEnable()) return "sdcard unable!"; return Environment.getDataDirectory().getPath(); }
From source file:com.error.hunter.ListenService.java
private void generateBugReport(ActivityManager.ProcessErrorStateInfo entry) { String condition;/* w w w . j a va 2 s. c om*/ badProcess = entry.processName; String build = Build.DISPLAY; String fingerprint = Build.FINGERPRINT; String serial = Build.SERIAL; String product = Build.PRODUCT; String model = Build.MODEL; File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); @SuppressWarnings("deprecation") long blockSize = stat.getBlockSize(); @SuppressWarnings("deprecation") long availableBlocks = stat.getAvailableBlocks(); String memory = Formatter.formatFileSize(this, availableBlocks * blockSize).toString(); MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long availableMegs = mi.availMem / 1048576L; strBuf.append("Problem detected in: ").append(badProcess); if (entry.tag != null) { strBuf.append(" (").append(entry.tag).append(")"); } strBuf.append("\nDevice product: " + product); strBuf.append("\nDevice model: " + model); strBuf.append("\nDevice build: " + build); strBuf.append("\nDevice fingerprint: " + fingerprint); strBuf.append("\nDevice SN: " + serial); strBuf.append("\nDevice available RAM (MB): " + availableMegs); strBuf.append("\nDevice free phisical memory: " + memory + "\n"); strBuf.append(getNetworkInfo()); strBuf.append("\n"); ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> procInfos = actvityManager.getRunningServices(1000); Iterator<RunningServiceInfo> taskIter = procInfos.iterator(); RunningServiceInfo info; while (taskIter.hasNext()) { info = taskIter.next(); if (info.process.equals(badProcess)) { strBuf.append("\nService " + info.service + " crash count: " + info.crashCount + " active since: " + info.activeSince + " process: " + info.process); } } strBuf.append("\n"); //android.os.Debug.MemoryInfo[] miPid = activityManager.getProcessMemoryInfo(new int[]{entry.pid}); //String memoryProc = miPid[0].toString(); //strBuf.append("\nRAM used by process (Process: " + entry.processName + " PID: " + entry.pid +"): " + memoryProc + "MB\n"); switch (entry.condition) { case ActivityManager.ProcessErrorStateInfo.CRASHED: condition = "CRASHED"; getDeviceProcessInfo(badProcess, entry.stackTrace); writeLogsToFile(condition, badProcess); break; case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING: condition = "ANR"; getDeviceProcessInfo(badProcess, ""); writeLogsToFile(condition, badProcess); break; default: condition = "<unknown>"; getDeviceProcessInfo(badProcess, entry.stackTrace); writeLogsToFile(condition, badProcess); break; } }
From source file:rus.cpuinfo.AndroidDepedentModel.DevInfo.java
@NonNull @SuppressLint("NewApi") private String getInternalStorage() { StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); final long blockCount = VersionUtil.IS_JELLY_BEAN_MR2() ? statFs.getBlockCountLong() * statFs.getBlockSizeLong() : statFs.getBlockCount() * statFs.getBlockSize(); // return String.format(Locale.getDefault(),"%s",blockCount); return formatFileSize(getContext(), blockCount); }
From source file:rus.cpuinfo.AndroidDepedentModel.DevInfo.java
@NonNull @SuppressLint("NewApi") private String getAviableStorage() { StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); final long availBlocks = VersionUtil.IS_JELLY_BEAN_MR2() ? statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong() : statFs.getAvailableBlocks() * statFs.getBlockSize(); // return String.format(Locale.getDefault(),"%s",availBlocks); return formatFileSize(getContext(), availBlocks).replaceAll(",", "."); }
From source file:com.jerrellmardis.amphitheatre.util.Utils.java
public static void backupDatabase(Context ctx) { try {// w w w . j av a 2 s . co m File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath = "//data//" + ctx.getApplicationContext().getPackageName() + "//databases//amphitheatre.db"; String backupDBPath = "amphitheatre.db"; File currentDB = new File(data, currentDBPath); File backupDB = new File(sd, backupDBPath); if (currentDB.exists()) { FileChannel src = new FileInputStream(currentDB).getChannel(); FileChannel dst = new FileOutputStream(backupDB).getChannel(); dst.transferFrom(src, 0, src.size()); src.close(); dst.close(); } } } catch (Exception e) { Log.i(Utils.class.getSimpleName(), "Unable to backup database"); } }
From source file:in.neoandroid.neoupdate.neoUpdate.java
/** * file:// implies local filesystem/*from www . j a v a2 s . com*/ * @param baseUrl * @param tmpDir * @param nSimultaneousConnections */ public neoUpdate(Context c, String baseUrl, String tmpDir, String appToken, String appSecret, int nSimultaneousConnections) { this.baseUrl = baseUrl; this.tmpDir = tmpDir; this.appToken = appToken; this.appSecret = appSecret; nConnections = nSimultaneousConnections; context = c; if (nConnections <= 0) nConnections = 1; // Check for local filesystem if (baseUrl.startsWith("file:///") || appToken == null || appSecret == null) { nConnections = 0; this.baseUrl = baseUrl.replace("file:///", "/"); fromOfflineStorage = true; if (baseUrl.endsWith(".npk")) fromNPKStorage = true; } else { this.baseUrl = serverUrl + baseUrl; if (this.baseUrl.endsWith("/")) this.baseUrl = this.baseUrl.substring(0, this.baseUrl.length() - 1); lock = new ReentrantLock(); } filesToDownload = new ArrayList<NewAsset>(); deviceID = Settings.Secure.getString(c.getContentResolver(), Settings.Secure.ANDROID_ID); serialNo = neoUpdate.getSerialNo(); macAddress = getWifiMac(c); if (deviceID == null) deviceID = ""; if (serialNo == null) serialNo = ""; if (macAddress == null) macAddress = ""; try { packageInfo = c.getPackageManager().getPackageInfo(c.getPackageName(), 0); } catch (Exception e) { } db = new neoUpdateDB(c); stopped = false; totalFilesToDownload = 0; if (enableDebug) { Log.d(TAG, "DeviceID: " + deviceID); Log.d(TAG, "serialNo: " + serialNo); Log.d(TAG, "MAC Address: " + macAddress); Log.d(TAG, "SDCard: " + Environment.getExternalStorageDirectory().getAbsolutePath()); Log.d(TAG, "Data: " + Environment.getDataDirectory().getAbsolutePath()); } }
From source file:com.wso2.mobile.mdm.api.DeviceInfo.java
/** *Returns the available internal memory size */// w w w.j a va2 s . c o m public double getAvailableInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); double blockSize = stat.getBlockSize(); double availableBlocks = stat.getAvailableBlocks(); return formatSizeGB(availableBlocks * blockSize); }