List of usage examples for android.os Environment MEDIA_MOUNTED_READ_ONLY
String MEDIA_MOUNTED_READ_ONLY
To view the source code for android.os Environment MEDIA_MOUNTED_READ_ONLY.
Click Source Link
From source file:com.lazy.gank.logging.Logcat.java
/** * msg //www . j ava 2 s . co m * * @param msg * @param logFileName log ?? */ private static void saveLog2File(String msg, String logFileName) { FileWriter objFilerWriter = null; BufferedWriter objBufferedWriter = null; do { // ??? String state = Environment.getExternalStorageState(); // SD ? if (!Environment.MEDIA_MOUNTED.equals(state)) { Log.d(TAG, "Not mount SD card!"); break; } // SD ??? if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { Log.d(TAG, "Not allow write SD card!"); break; } File rootPath = new File(sLogFolderPath); if (rootPath.exists()) { File fileLogFilePath = new File(sLogFolderPath, logFileName); // ? if (true != fileLogFilePath.exists()) { try { fileLogFilePath.createNewFile(); } catch (IOException e) { e.printStackTrace(); break; } } // ?? if (true != fileLogFilePath.exists()) { Log.d(TAG, "Create log file failed!"); break; } try { objFilerWriter = new FileWriter(fileLogFilePath, // true); // ? } catch (IOException e1) { Log.d(TAG, "New FileWriter Instance failed"); e1.printStackTrace(); break; } objBufferedWriter = new BufferedWriter(objFilerWriter); try { objBufferedWriter.write(msg); objBufferedWriter.flush(); } catch (IOException e) { Log.d(TAG, "objBufferedWriter.write or objBufferedWriter.flush failed"); e.printStackTrace(); } } else { Log.d(TAG, "Log savePaht invalid!"); } } while (false); if (null != objBufferedWriter) { try { objBufferedWriter.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != objFilerWriter) { try { objFilerWriter.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.example.android.wearable.runtimepermissions.MainPhoneActivity.java
private String getPhoneStorageInformation() { StringBuilder stringBuilder = new StringBuilder(); String state = Environment.getExternalStorageState(); boolean isExternalStorageReadable = Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state); if (isExternalStorageReadable) { File externalStorageDirectory = Environment.getExternalStorageDirectory(); String[] fileList = externalStorageDirectory.list(); if (fileList.length > 0) { stringBuilder.append("List of files\n"); for (String file : fileList) { stringBuilder.append(" - " + file + "\n"); }/* w w w . j a v a 2 s . co m*/ } else { stringBuilder.append("No files in external storage."); } } else { stringBuilder.append("No external media is available."); } return stringBuilder.toString(); }
From source file:com.jefftharris.passwdsafe.file.PasswdFileUri.java
/** Resolve fields for a file URI */ private void resolveFileUri() { boolean writable; Integer extraMsgId = null;//from w w w . j a va2s. c om do { if ((itsFile == null) || !itsFile.canWrite()) { writable = false; break; } // Check mount state on kitkat or higher if (ApiCompat.SDK_VERSION < ApiCompat.SDK_KITKAT) { writable = true; break; } writable = !EnvironmentCompat.getStorageState(itsFile).equals(Environment.MEDIA_MOUNTED_READ_ONLY); if (!writable) { extraMsgId = R.string.read_only_media; } } while (false); itsWritableInfo = new Pair<>(writable, extraMsgId); itsIsDeletable = writable; }
From source file:co.nerdart.ourss.fragment.FeedsListFragment.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { setFeedSortEnabled(false);// w w w. j a va2 s. c o m switch (item.getItemId()) { case R.id.menu_add_feed: { startActivity(new Intent(Intent.ACTION_INSERT).setData(FeedColumns.CONTENT_URI)); return true; } case R.id.menu_refresh: { if (!FetcherService.isRefreshingFeeds) { getActivity().startService( new Intent(getActivity(), FetcherService.class).setAction(Constants.ACTION_REFRESH_FEEDS)); } return true; } case R.id.menu_settings: { startActivity(new Intent(getActivity(), GeneralPrefsActivity.class)); return true; } case R.id.menu_all_read: { new Thread() { @Override public void run() { ContentResolver cr = getActivity().getContentResolver(); if (cr.update(EntryColumns.CONTENT_URI, FeedData.getReadContentValues(), EntryColumns.WHERE_UNREAD, null) > 0) { cr.notifyChange(FeedColumns.CONTENT_URI, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); cr.notifyChange(EntryColumns.FAVORITES_CONTENT_URI, null); } } }.start(); return true; } case R.id.menu_add_group: { final EditText input = new EditText(getActivity()); input.setSingleLine(true); new AlertDialog.Builder(getActivity()) // .setTitle(R.string.add_group_title) // .setView(input) // // .setMessage(R.string.add_group_sentence) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new Thread() { @Override public void run() { String groupName = input.getText().toString(); if (!groupName.isEmpty()) { ContentResolver cr = getActivity().getContentResolver(); ContentValues values = new ContentValues(); values.put(FeedColumns.IS_GROUP, true); values.put(FeedColumns.NAME, groupName); cr.insert(FeedColumns.GROUPS_CONTENT_URI, values); } } }.start(); } }).setNegativeButton(android.R.string.cancel, null).show(); return true; } case R.id.menu_import: { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.select_file); try { final String[] fileNames = Environment.getExternalStorageDirectory().list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return new File(dir, filename).isFile(); } }); builder.setItems(fileNames, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { new Thread(new Runnable() { // To not block the UI @Override public void run() { try { OPML.importFromFile(Environment.getExternalStorageDirectory().toString() + File.separator + fileNames[which]); } catch (Exception e) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { Crouton.makeText(getActivity(), R.string.error_feed_import, Style.INFO); } }); } } }).start(); } }); builder.show(); } catch (Exception e) { Crouton.makeText(getActivity(), R.string.error_feed_import, Style.INFO); } } else { Crouton.makeText(getActivity(), R.string.error_external_storage_not_available, Style.INFO); } return true; } case R.id.menu_export: { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { new Thread(new Runnable() { // To not block the UI @Override public void run() { try { final String filename = Environment.getExternalStorageDirectory().toString() + "/OURSS_" + System.currentTimeMillis() + ".opml"; OPML.exportToFile(filename); getActivity().runOnUiThread(new Runnable() { @Override public void run() { //Toast.makeText(getActivity(), // String.format // (getString(R.string.message_exported_to), // filename),Toast.LENGTH_LONG).show(); Crouton.makeText(getActivity(), String.format(getString(R.string.message_exported_to), filename), Style.INFO); } }); } catch (Exception e) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { //Toast.makeText(getActivity(), // R.string.error_feed_export, // Toast.LENGTH_LONG).show(); Crouton.makeText(getActivity(), R.string.error_feed_export, Style.INFO); } }); } } }).start(); } else { //Toast.makeText(getActivity(), R.string.error_external_storage_not_available, // Toast.LENGTH_LONG).show(); Crouton.makeText(getActivity(), R.string.error_external_storage_not_available, Style.INFO); } break; } case R.id.menu_enable_feed_sort: { setFeedSortEnabled(true); return true; } case R.id.menu_disable_feed_sort: { // do nothing as the feed sort gets disabled anyway return true; } } return super.onOptionsItemSelected(item); }
From source file:at.tomtasche.reader.ui.activity.DocumentActivity.java
public void handleError(Throwable error, final Uri uri) { Log.e("OpenDocument Reader", "Error opening file at " + uri.toString(), error); final Uri cacheUri = AndroidFileCache.getCacheFileUri(); for (LoadingListener listener : loadingListeners) { listener.onError(error, uri);/* w w w. j a va 2 s .co m*/ // TODO: return here, but only if the listener was registered by a // JUnit test } int errorDescription; if (error == null) { return; } else if (error instanceof EncryptedDocumentException) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.toast_error_password_protected); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); builder.setView(input); builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { loadUri(cacheUri, input.getText().toString()); dialog.dismiss(); } }); builder.setNegativeButton(getString(android.R.string.cancel), null); builder.show(); return; } else if (error instanceof IllegalMimeTypeException || error instanceof ZipException || error instanceof ZipEntryNotFoundException || error instanceof UnsupportedMimeTypeException) { /*AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.toast_error_illegal_file); builder.setMessage(R.string.dialog_upload_file); builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { uploadUri(cacheUri); dialog.dismiss(); } }); builder.setNegativeButton(getString(android.R.string.cancel), null); builder.show();*/ return; } else if (error instanceof FileNotFoundException) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY) || Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { errorDescription = R.string.toast_error_find_file; } else { errorDescription = R.string.toast_error_storage; } } else if (error instanceof IllegalArgumentException) { errorDescription = R.string.toast_error_illegal_file; } else if (error instanceof OutOfMemoryError) { errorDescription = R.string.toast_error_out_of_memory; } else { errorDescription = R.string.toast_error_generic; } showCrouton(errorDescription, null, AppMsg.STYLE_ALERT); }
From source file:com.Candy.sizer.CandySizer.java
public short sdAvailable() { // check if sdcard is available // taken from developer.android.com short mExternalStorageAvailable = 0; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = 2;//from w w w .j a v a 2 s . c o m } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = 1; } else { // Something else is wrong. It may be one of many other states, but // all we need // to know is we can neither read nor write mExternalStorageAvailable = 0; } return mExternalStorageAvailable; }
From source file:com.lastorder.pushnotifications.data.ImageDownloader.java
public void saveToSDCard(Bitmap bitmap, String name, String nam) { boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { mExternalStorageAvailable = mExternalStorageWriteable = true; Log.v(LOG_TAG, "SD Card is available for read and write " + mExternalStorageAvailable + mExternalStorageWriteable); saveFile(bitmap, name, nam);// ww w. j a va 2s .c o m } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { mExternalStorageAvailable = true; mExternalStorageWriteable = false; Log.v(LOG_TAG, "SD Card is available for read " + mExternalStorageAvailable); } else { mExternalStorageAvailable = mExternalStorageWriteable = false; Log.v(LOG_TAG, "Please insert a SD Card to save your Video " + mExternalStorageAvailable + mExternalStorageWriteable); } }
From source file:com.kncwallet.wallet.ui.WalletActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); final Resources res = getResources(); final String externalStorageState = Environment.getExternalStorageState(); menu.findItem(R.id.wallet_options_exchange_rates) .setVisible(res.getBoolean(R.bool.show_exchange_rates_option)); menu.findItem(R.id.wallet_options_import_keys) .setEnabled(Environment.MEDIA_MOUNTED.equals(externalStorageState) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalStorageState)); menu.findItem(R.id.wallet_options_export_keys) .setEnabled(Environment.MEDIA_MOUNTED.equals(externalStorageState)); return true;/*from w w w .j a va 2 s.c o m*/ }
From source file:com.denel.facepatrol.MainActivity.java
private void updateExternalStorageState() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { mExternalStorageAvailable = mExternalStorageWritable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { mExternalStorageAvailable = true; mExternalStorageWritable = false; } else {/* w ww . j a v a 2s . com*/ mExternalStorageAvailable = mExternalStorageWritable = false; } }
From source file:gr.ioanpier.auth.users.memorypaintings.MainActivityFragment.java
private boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state); }