List of usage examples for android.os Environment getDataDirectory
public static File getDataDirectory()
From source file:biz.bokhorst.xprivacy.Util.java
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/*from w w w .j ava2s . co m*/ dataDir += "user" + File.separator + userId; dataDir += File.separator + Util.class.getPackage().getName(); return dataDir; }
From source file:de.cachebox_test.splash.java
@SuppressWarnings("deprecation") @Override/* w ww. ja v a 2s.c o m*/ protected void onStart() { super.onStart(); Log.debug(log, "onStart"); if (android.os.Build.VERSION.SDK_INT >= 23) { PermissionCheck.checkNeededPermissions(this); } // initial GDX Gdx.files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath()); // first, try to find stored preferences of workPath androidSetting = this.getSharedPreferences(Global.PREFS_NAME, 0); workPath = androidSetting.getString("WorkPath", Environment.getDataDirectory() + "/cachebox"); boolean askAgain = androidSetting.getBoolean("AskAgain", true); showSandbox = androidSetting.getBoolean("showSandbox", false); Global.initTheme(this); Global.InitIcons(this); CB_Android_FileExplorer fileExplorer = new CB_Android_FileExplorer(this); PlatformConnector.setGetFileListener(fileExplorer); PlatformConnector.setGetFolderListener(fileExplorer); String LangPath = androidSetting.getString("Sel_LanguagePath", ""); if (LangPath.length() == 0) { // set default lang String locale = Locale.getDefault().getLanguage(); if (locale.contains("de")) { LangPath = "data/lang/de/strings.ini"; } else if (locale.contains("cs")) { LangPath = "data/lang/cs/strings.ini"; } else if (locale.contains("cs")) { LangPath = "data/lang/cs/strings.ini"; } else if (locale.contains("fr")) { LangPath = "data/lang/fr/strings.ini"; } else if (locale.contains("nl")) { LangPath = "data/lang/nl/strings.ini"; } else if (locale.contains("pl")) { LangPath = "data/lang/pl/strings.ini"; } else if (locale.contains("pt")) { LangPath = "data/lang/pt/strings.ini"; } else if (locale.contains("hu")) { LangPath = "data/lang/hu/strings.ini"; } else { LangPath = "data/lang/en-GB/strings.ini"; } } new Translation(workPath, FileType.Internal); try { Translation.LoadTranslation(LangPath); } catch (Exception e) { e.printStackTrace(); } // check Write permission if (!askAgain) { if (!FileIO.checkWritePermission(workPath)) { askAgain = true; if (!ToastEx) { ToastEx = true; String WriteProtectionMsg = Translation.Get("NoWriteAcces"); Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show(); } } } if ((askAgain)) { // no saved workPath found -> search sd-cards and if more than 1 is found give the user the possibility to select one String externalSd = getExternalSdPath("/CacheBox"); boolean hasExtSd; final String externalSd2 = externalSd; if (externalSd != null) { hasExtSd = (externalSd.length() > 0) && (!externalSd.equalsIgnoreCase(workPath)); } else { hasExtSd = false; } // externe SD wurde gefunden != internal // oder Tablet Layout mglich // -> Auswahldialog anzeigen try { final Dialog dialog = new Dialog(context) { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { splash.this.finish(); } return super.onKeyDown(keyCode, event); } }; dialog.setContentView(R.layout.sdselectdialog); TextView title = (TextView) dialog.findViewById(R.id.select_sd_title); title.setText(Translation.Get("selectWorkSpace") + "\n\n"); /* * TextView tbLayout = (TextView) dialog.findViewById(R.id.select_sd_layout); tbLayout.setText("\nLayout"); final RadioGroup * rgLayout = (RadioGroup) dialog.findViewById(R.id.select_sd_radiogroup); final RadioButton rbHandyLayout = (RadioButton) * dialog.findViewById(R.id.select_sd_handylayout); final RadioButton rbTabletLayout = (RadioButton) * dialog.findViewById(R.id.select_sd_tabletlayout); rbHandyLayout.setText("Handy-Layout"); * rbTabletLayout.setText("Tablet-Layout"); if (!GlobalCore.posibleTabletLayout) { * rgLayout.setVisibility(RadioGroup.INVISIBLE); rbHandyLayout.setChecked(true); } else { if (GlobalCore.isTab) { * rbTabletLayout.setChecked(true); } else { rbHandyLayout.setChecked(true); } } */ final CheckBox cbAskAgain = (CheckBox) dialog.findViewById(R.id.select_sd_askagain); cbAskAgain.setText(Translation.Get("AskAgain")); cbAskAgain.setChecked(askAgain); Button buttonI = (Button) dialog.findViewById(R.id.button1); buttonI.setText("Internal SD\n\n" + workPath); buttonI.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use internal SD -> nothing to change Thread thread = new Thread() { @Override public void run() { boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); dialog.dismiss(); startInitial(); } }; thread.start(); } }); Button buttonE = (Button) dialog.findViewById(R.id.button2); final boolean isSandbox = externalSd == null ? false : externalSd.contains("Android/data/de.cachebox_test"); if (!hasExtSd) { buttonE.setVisibility(Button.INVISIBLE); } else { String extSdText = isSandbox ? "External SD SandBox\n\n" : "External SD\n\n"; buttonE.setText(extSdText + externalSd); } buttonE.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show KitKat Massage? if (isSandbox && !showSandbox) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set title alertDialogBuilder.setTitle("KitKat Sandbox"); // set dialog message alertDialogBuilder.setMessage(Translation.Get("Desc_Sandbox")).setCancelable(false) .setPositiveButton(Translation.Get("yes"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, run Sandbox Path showSandbox = true; Config.AcceptChanges(); // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = externalSd2; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } }) .setNegativeButton(Translation.Get("no"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } else { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = externalSd2; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } } }); LinearLayout ll = (LinearLayout) dialog.findViewById(R.id.scrollViewLinearLayout); // add all Buttons for created Workspaces AdditionalWorkPathArray = getAdditionalWorkPathArray(); for (final String AddWorkPath : AdditionalWorkPathArray) { final String Name = FileIO.GetFileNameWithoutExtension(AddWorkPath); if (!FileIO.checkWritePermission(AddWorkPath)) { // delete this Work Path deleteWorkPath(AddWorkPath); continue; } Button buttonW = new Button(context); buttonW.setText(Name + "\n\n" + AddWorkPath); buttonW.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // setting the MassageBox then the UI_sizes are not initial in this moment Resources res = splash.this.getResources(); float scale = res.getDisplayMetrics().density; float calcBase = 533.333f * scale; FrameLayout frame = (FrameLayout) findViewById(R.id.frameLayout1); int width = frame.getMeasuredWidth(); int height = frame.getMeasuredHeight(); MessageBox.Builder.WindowWidth = width; MessageBox.Builder.WindowHeight = height; MessageBox.Builder.textSize = (calcBase / res.getDimensionPixelSize(R.dimen.BtnTextSize)) * scale; MessageBox.Builder.ButtonHeight = (int) (50 * scale); // Ask before delete msg = (MessageBox) MessageBox.Show(Translation.Get("shuredeleteWorkspace", Name), Translation.Get("deleteWorkspace"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (which == MessageBox.BUTTON_POSITIVE) { // Delete this Workpath only from Settings don't delete any File deleteWorkPath(AddWorkPath); } // Start again to exclude the old Folder msg.dismiss(); onStart(); } }); dialog.dismiss(); return true; } }); buttonW.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); // show please wait dialog showPleaseWaitDialog(); // use external SD -> change workPath Thread thread = new Thread() { @Override public void run() { workPath = AddWorkPath; boolean askAgain = cbAskAgain.isChecked(); // boolean useTabletLayout = rbTabletLayout.isChecked(); saveWorkPath(askAgain/* , useTabletLayout */); startInitial(); } }; thread.start(); } }); ll.addView(buttonW); } Button buttonC = (Button) dialog.findViewById(R.id.buttonCreateWorkspace); buttonC.setText(Translation.Get("createWorkSpace")); buttonC.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // close select dialog dialog.dismiss(); getFolderReturnListener = new IgetFolderReturnListener() { @Override public void getFolderReturn(String Path) { if (FileIO.checkWritePermission(Path)) { AdditionalWorkPathArray.add(Path); writeAdditionalWorkPathArray(AdditionalWorkPathArray); // Start again to include the new Folder onStart(); } else { String WriteProtectionMsg = Translation.Get("NoWriteAcces"); Toast.makeText(splash.this, WriteProtectionMsg, Toast.LENGTH_LONG).show(); } } }; PlatformConnector.getFolder("", Translation.Get("select_folder"), Translation.Get("select"), getFolderReturnListener); } }); dialog.show(); } catch (Exception ex) { ex.printStackTrace(); } } else { if (GlobalCore.displayType == DisplayType.Large || GlobalCore.displayType == DisplayType.xLarge) GlobalCore.isTab = isLandscape; // restore the saved workPath // test whether workPath is available by checking the free size on the SD String workPathToTest = workPath.substring(0, workPath.lastIndexOf("/")); long bytesAvailable = 0; try { StatFs stat = new StatFs(workPathToTest); bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockCount(); } catch (Exception ex) { bytesAvailable = 0; } if (bytesAvailable == 0) { // there is a workPath stored but this workPath is not available at the moment (maybe SD is removed) Toast.makeText(splashActivity, "WorkPath " + workPath + " is not available!\nMaybe SD-Card is removed?", Toast.LENGTH_LONG) .show(); finish(); return; } startInitial(); } }
From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java
/** * create a file to save photo/*from www . j ava 2 s. c om*/ * @param ctx * @return */ private File createImageSaveFile(Context ctx) { if (Util.isStorageEnable()) { // File pic = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (!pic.exists()) { pic.mkdirs(); } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = "IMG_" + timeStamp; File tmpFile = new File(pic, fileName + ".jpg"); mCurrentPhotoPath = tmpFile.getAbsolutePath(); Log.i(TAG, "=====camera path:" + mCurrentPhotoPath); return tmpFile; } else { //File cacheDir = ctx.getCacheDir(); File cacheDir = Environment.getDataDirectory(); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = "IMG_" + timeStamp; File tmpFile = new File(cacheDir, fileName + ".jpg"); mCurrentPhotoPath = tmpFile.getAbsolutePath(); Log.i(TAG, "=====camera path:" + mCurrentPhotoPath); return tmpFile; } }
From source file:biz.bokhorst.xprivacy.Util.java
public static boolean hasLBE() { if (mHasLBE == null) { mHasLBE = false;/*from w ww . j av a 2s .com*/ try { File apps = new File(Environment.getDataDirectory() + File.separator + "app"); File[] files = (apps == null ? null : apps.listFiles()); if (files != null) for (File file : files) if (file.getName().startsWith("com.lbe.security")) { mHasLBE = true; break; } } catch (Throwable ex) { Util.bug(null, ex); } } return mHasLBE; }
From source file:com.pizidea.imagepicker.AndroidImagePicker.java
/** * create a file to save photo//w w w.ja v a2 s .co m * * @param ctx * @return */ private File createImageSaveFile(Context ctx) { if (Util.isStorageEnable()) { // File pic = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); if (!pic.exists()) { pic.mkdirs(); } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = "IMG_" + timeStamp; File tmpFile = new File(pic, fileName + ".jpg"); mCurrentPhotoPath = tmpFile.getAbsolutePath(); Log.i(TAG, "=====camera path:" + mCurrentPhotoPath); return tmpFile; } else { //File cacheDir = ctx.getCacheDir(); File cacheDir = Environment.getDataDirectory(); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()); String fileName = "IMG_" + timeStamp; File tmpFile = new File(cacheDir, fileName + ".jpg"); mCurrentPhotoPath = tmpFile.getAbsolutePath(); Log.i(TAG, "=====camera path:" + mCurrentPhotoPath); return tmpFile; } }
From source file:de.baumann.quitsmoking.fragments.FragmentNotes.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_backup) { final CharSequence[] options = { getString(R.string.action_backup), getString(R.string.action_restore), getString(R.string.action_delete) }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setItems(options, new DialogInterface.OnClickListener() { @Override/*from w ww . j a va2s . co m*/ public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.action_backup))) { sharedPref.edit().putString("sortDB", "title").apply(); setNotesList(); File directory = new File( Environment.getExternalStorageDirectory() + "/QuitSmoking/backup/"); if (!directory.exists()) { //noinspection ResultOfMethodCallIgnored directory.mkdirs(); } try { File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath2 = "//data//" + "de.baumann.quitsmoking" + "//databases//" + "notes.db"; String backupDBPath2 = "//QuitSmoking//" + "//backup//" + "notes.db"; File currentDB2 = new File(data, currentDBPath2); File backupDB2 = new File(sd, backupDBPath2); FileChannel src2 = new FileInputStream(currentDB2).getChannel(); FileChannel dst2 = new FileOutputStream(backupDB2).getChannel(); dst2.transferFrom(src2, 0, src2.size()); src2.close(); dst2.close(); Snackbar snackbar = Snackbar.make(listView, R.string.toast_backup, Snackbar.LENGTH_LONG); snackbar.show(); } } catch (Exception e) { Snackbar snackbar = Snackbar.make(listView, R.string.toast_backup_not, Snackbar.LENGTH_LONG); snackbar.show(); } } if (options[item].equals(getString(R.string.action_restore))) { sharedPref.edit().putString("sortDB", "seqno").apply(); setNotesList(); try { File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if (sd.canWrite()) { String currentDBPath2 = "//data//" + "de.baumann.quitsmoking" + "//databases//" + "notes.db"; String backupDBPath2 = "//QuitSmoking//" + "//backup//" + "notes.db"; File currentDB2 = new File(data, currentDBPath2); File backupDB2 = new File(sd, backupDBPath2); FileChannel src2 = new FileInputStream(backupDB2).getChannel(); FileChannel dst2 = new FileOutputStream(currentDB2).getChannel(); dst2.transferFrom(src2, 0, src2.size()); src2.close(); dst2.close(); Snackbar snackbar = Snackbar.make(listView, R.string.toast_restore, Snackbar.LENGTH_LONG); snackbar.show(); setNotesList(); } } catch (Exception e) { Snackbar snackbar = Snackbar.make(listView, R.string.toast_restore_not, Snackbar.LENGTH_LONG); snackbar.show(); } } if (options[item].equals(getString(R.string.action_delete))) { sharedPref.edit().putString("sortDB", "icon").apply(); setNotesList(); Snackbar snackbar = Snackbar .make(listView, R.string.note_delete_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.yes, new View.OnClickListener() { @Override public void onClick(View view) { getActivity().deleteDatabase("notes.db"); setNotesList(); } }); snackbar.show(); } } }); builder.setPositiveButton(R.string.goal_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); builder.show(); } if (id == R.id.action_sort) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_sort, null); final CheckBox ch_title = (CheckBox) dialogView.findViewById(R.id.checkBoxTitle); final CheckBox ch_create = (CheckBox) dialogView.findViewById(R.id.checkBoxCreate); final CheckBox ch_edit = (CheckBox) dialogView.findViewById(R.id.checkBoxEdit); final CheckBox ch_icon = (CheckBox) dialogView.findViewById(R.id.checkBoxIcon); final CheckBox ch_att = (CheckBox) dialogView.findViewById(R.id.checkBoxAtt); if (sharedPref.getString("sortDB", "title").equals("title")) { ch_title.setChecked(true); } else { ch_title.setChecked(false); } if (sharedPref.getString("sortDB", "title").equals("create")) { ch_create.setChecked(true); } else { ch_create.setChecked(false); } if (sharedPref.getString("sortDB", "title").equals("seqno")) { ch_edit.setChecked(true); } else { ch_edit.setChecked(false); } if (sharedPref.getString("sortDB", "title").equals("icon")) { ch_icon.setChecked(true); } else { ch_icon.setChecked(false); } if (sharedPref.getString("sortDB", "title").equals("attachment")) { ch_att.setChecked(true); } else { ch_att.setChecked(false); } ch_title.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ch_create.setChecked(false); ch_edit.setChecked(false); ch_icon.setChecked(false); ch_att.setChecked(false); sharedPref.edit().putString("sortDB", "title").apply(); setNotesList(); } } }); ch_create.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ch_edit.setChecked(false); ch_icon.setChecked(false); ch_title.setChecked(false); ch_att.setChecked(false); sharedPref.edit().putString("sortDB", "create").apply(); setNotesList(); } } }); ch_edit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ch_create.setChecked(false); ch_icon.setChecked(false); ch_title.setChecked(false); ch_att.setChecked(false); sharedPref.edit().putString("sortDB", "seqno").apply(); setNotesList(); } } }); ch_icon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ch_create.setChecked(false); ch_edit.setChecked(false); ch_title.setChecked(false); ch_att.setChecked(false); sharedPref.edit().putString("sortDB", "icon").apply(); setNotesList(); } } }); ch_att.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { ch_create.setChecked(false); ch_edit.setChecked(false); ch_title.setChecked(false); ch_icon.setChecked(false); sharedPref.edit().putString("sortDB", "attachment").apply(); setNotesList(); } } }); builder.setView(dialogView); builder.setTitle(R.string.action_sort); builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); return true; } if (id == R.id.action_note) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); String dateCreate = format.format(date); sharedPref.edit().putString("handleTextCreate", dateCreate).apply(); helper_notes.editNote(getActivity()); } return super.onOptionsItemSelected(item); }
From source file:com.adobe.phonegap.contentsync.Sync.java
private long getFreeSpace() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; }
From source file:in.neoandroid.neoupdate.neoUpdate.java
private String mapPath(String path) { String ret = path;/*w w w . j ava 2 s . c o m*/ if (path.startsWith("/sdcard/")) path.replaceFirst("/sdcard/", Environment.getExternalStorageDirectory().getAbsolutePath() + "/"); if (path.startsWith("/data/")) path.replaceFirst("/data/", Environment.getDataDirectory().getAbsolutePath() + "/"); return ret; }
From source file:com.almalence.util.Util.java
/************************************************************************************************* * Returns size in MegaBytes.// w ww. j a v a2s .c o m * * If you need calculate external memory, change this: StatFs statFs = new * StatFs(Environment.getRootDirectory().getAbsolutePath()); to this: StatFs * statFs = new * StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); **************************************************************************************************/ public static long TotalDeviceMemory() { StatFs statFs = new StatFs(Environment.getDataDirectory().getPath()); long blockSize = statFs.getBlockSize(); long blockCount = statFs.getBlockCount(); return (blockCount * blockSize) / 1048576; }
From source file:com.almalence.util.Util.java
public static long FreeDeviceMemory() { StatFs statFs = new StatFs(Environment.getDataDirectory().getPath()); long blockSize = statFs.getBlockSize(); long availableBloks = statFs.getAvailableBlocks(); return (availableBloks * blockSize) / 1048576; }