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.makotosan.vimeodroid.vimeo.Methods.java
public static boolean isExternalStorageWritable() { boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else {//from ww w.ja v a2s.com mExternalStorageAvailable = mExternalStorageWriteable = false; } return mExternalStorageAvailable && mExternalStorageWriteable; }
From source file:com.otaupdater.DownloadsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String extState = Environment.getExternalStorageState(); if (!extState.equals(Environment.MEDIA_MOUNTED) && !extState.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { Toast.makeText(this, extState.equals(Environment.MEDIA_SHARED) ? R.string.toast_nosd_shared : R.string.toast_nosd_error, Toast.LENGTH_LONG).show(); finish();/*w w w . ja v a2 s. c o m*/ } setContentView(R.layout.downloads); dlFragment = (DownloadListFragment) getFragmentManager().findFragmentById(R.id.download_list); Fragment adFragment = getFragmentManager().findFragmentById(R.id.ads); if (adFragment != null) getFragmentManager().beginTransaction().hide(adFragment).commit(); bar = getActionBar(); assert bar != null; bar.setDisplayHomeAsUpEnabled(true); bar.setDisplayShowTitleEnabled(false); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); bar.setListNavigationCallbacks(ArrayAdapter.createFromResource(this, R.array.download_types, android.R.layout.simple_spinner_dropdown_item), this); int state = -1; String action = getIntent().getAction(); if (action != null) { if (action.equals(FLASH_ROM_ACTION)) { state = GOTO_TYPE_ROM; showFlashDialog(RomInfo.FACTORY.fromIntent(getIntent())); } else if (action.equals(FLASH_KERNEL_ACTION)) { state = GOTO_TYPE_KERNEL; showFlashDialog(KernelInfo.FACTORY.fromIntent(getIntent())); } else { state = getIntent().getIntExtra(EXTRA_GOTO_TYPE, state); } } if (savedInstanceState != null) { if (state == -1) state = savedInstanceState.getInt("state", dlFragment.getState()); } bar.setSelectedNavigationItem(state); }
From source file:de.fmaul.android.cmis.utils.StorageUtils.java
public static File getDownloadRoot(Application app) throws StorageException { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { StringBuilder builder = new StringBuilder(); builder.append(((CmisApp) app).getPrefs().getDownloadFolder()); builder.append("/"); builder.append(ROOT_FOLDER_APP); return new File(builder.toString()); } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { throw new StorageException("Storage in Read Only Mode"); } else {/* ww w . ja v a2s. c o m*/ throw new StorageException("Storage is unavailable"); } }
From source file:com.radicaldynamic.groupinform.application.Collect.java
/** * Creates required directories on the SDCard (or other external storage) * @throws RuntimeException if there is no SDCard or the directory exists as a non directory */// w w w . j ava 2 s . com public static void createODKDirs() throws RuntimeException { String cardstatus = Environment.getExternalStorageState(); if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE) || cardstatus.equals(Environment.MEDIA_UNMOUNTED) || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY) || cardstatus.equals(Environment.MEDIA_SHARED)) { RuntimeException e = new RuntimeException( "ODK reports :: SDCard error: " + Environment.getExternalStorageState()); throw e; } String[] dirs = { ODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH }; for (String dirName : dirs) { File dir = new File(dirName); if (!dir.exists()) { if (!dir.mkdirs()) { RuntimeException e = new RuntimeException("ODK reports :: Cannot create directory: " + dirName); throw e; } } else { if (!dir.isDirectory()) { RuntimeException e = new RuntimeException( "ODK reports :: " + dirName + " exists, but is not a directory"); throw e; } } } }
From source file:org.yammp.app.MusicBrowserActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setVolumeControlStream(AudioManager.STREAM_MUSIC); mActionBar = getSupportActionBar();//from w w w . j a v a2 s . c om mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); String mount_state = Environment.getExternalStorageState(); if (!Environment.MEDIA_MOUNTED.equals(mount_state) && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(mount_state)) { startActivity(new Intent(this, ScanningProgress.class)); finish(); } FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(android.R.id.content, new MusicBrowserFragment()).commit(); //mAdapter = new PagesAdapter(mActionBar); //mAdapter.addPage(new MusicBrowserFragment(), "Music Library"); }
From source file:com.google.android.apps.location.gps.gnsslogger.FileLogger.java
/** * Start a new file logging process.//from w w w . j a v a2 s .c o m */ public void startNewLog() { synchronized (mFileLock) { File baseDirectory; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { baseDirectory = new File(Environment.getExternalStorageDirectory(), FILE_PREFIX); baseDirectory.mkdirs(); } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { logError("Cannot write to external storage."); return; } else { logError("Cannot read external storage."); return; } SimpleDateFormat formatter = new SimpleDateFormat("yyy_MM_dd_HH_mm_ss"); Date now = new Date(); String fileName = String.format("%s_%s.txt", FILE_PREFIX, formatter.format(now)); File currentFile = new File(baseDirectory, fileName); String currentFilePath = currentFile.getAbsolutePath(); BufferedWriter currentFileWriter; try { currentFileWriter = new BufferedWriter(new FileWriter(currentFile)); } catch (IOException e) { logException("Could not open file: " + currentFilePath, e); return; } // initialize the contents of the file try { currentFileWriter.write(COMMENT_START); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.write("Header Description:"); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.write(VERSION_TAG); String manufacturer = Build.MANUFACTURER; String model = Build.MODEL; String fileVersion = mContext.getString(R.string.app_version) + " Platform: " + Build.VERSION.RELEASE + " " + "Manufacturer: " + manufacturer + " " + "Model: " + model; currentFileWriter.write(fileVersion); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter .write("Raw,ElapsedRealtimeMillis,TimeNanos,LeapSecond,TimeUncertaintyNanos,FullBiasNanos," + "BiasNanos,BiasUncertaintyNanos,DriftNanosPerSecond,DriftUncertaintyNanosPerSecond," + "HardwareClockDiscontinuityCount,Svid,TimeOffsetNanos,State,ReceivedSvTimeNanos," + "ReceivedSvTimeUncertaintyNanos,Cn0DbHz,PseudorangeRateMetersPerSecond," + "PseudorangeRateUncertaintyMetersPerSecond," + "AccumulatedDeltaRangeState,AccumulatedDeltaRangeMeters," + "AccumulatedDeltaRangeUncertaintyMeters,CarrierFrequencyHz,CarrierCycles," + "CarrierPhase,CarrierPhaseUncertainty,MultipathIndicator,SnrInDb," + "ConstellationType,AgcDb,CarrierFrequencyHz"); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.write("Fix,Provider,Latitude,Longitude,Altitude,Speed,Accuracy,(UTC)TimeInMs"); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.write("Nav,Svid,Type,Status,MessageId,Sub-messageId,Data(Bytes)"); currentFileWriter.newLine(); currentFileWriter.write(COMMENT_START); currentFileWriter.newLine(); } catch (IOException e) { logException("Count not initialize file: " + currentFilePath, e); return; } if (mFileWriter != null) { try { mFileWriter.close(); } catch (IOException e) { logException("Unable to close all file streams.", e); return; } } mFile = currentFile; mFileWriter = currentFileWriter; Toast.makeText(mContext, "File opened: " + currentFilePath, Toast.LENGTH_SHORT).show(); // To make sure that files do not fill up the external storage: // - Remove all empty files FileFilter filter = new FileToDeleteFilter(mFile); for (File existingFile : baseDirectory.listFiles(filter)) { existingFile.delete(); } // - Trim the number of files with data File[] existingFiles = baseDirectory.listFiles(); int filesToDeleteCount = existingFiles.length - MAX_FILES_STORED; if (filesToDeleteCount > 0) { Arrays.sort(existingFiles); for (int i = 0; i < filesToDeleteCount; ++i) { existingFiles[i].delete(); } } } }
From source file:org.musicmod.android.app.MusicBrowserActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setVolumeControlStream(AudioManager.STREAM_MUSIC); mPrefs = new PreferencesEditor(getApplicationContext()); String mount_state = Environment.getExternalStorageState(); if (!Environment.MEDIA_MOUNTED.equals(mount_state) && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(mount_state)) { startActivity(new Intent(this, ScanningProgress.class)); finish();//from w w w .ja va2s . c o m } configureActivity(); configureTabs(icicle); }
From source file:com.manning.androidhacks.hack037.MainActivity.java
private boolean canWriteInExternalStorage() { boolean mExternalStorageAvailable = false; boolean mExternalStorageWriteable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false; } else {/* w w w. ja v a 2s. c o m*/ // 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 = mExternalStorageWriteable = false; } return mExternalStorageAvailable && mExternalStorageWriteable; }
From source file:it.fabaris.wfp.application.Collect.java
/** * Creates required directories on the SDCard (or other external storage) * @throws RuntimeException if there is no SDCard or the directory exists as a non directory *//*from w w w. j a v a 2s . c o m*/ public static void createODKDirs() throws RuntimeException { String cardstatus = Environment.getExternalStorageState(); if (cardstatus.equals(Environment.MEDIA_REMOVED) || cardstatus.equals(Environment.MEDIA_UNMOUNTABLE) || cardstatus.equals(Environment.MEDIA_UNMOUNTED) || cardstatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY) || cardstatus.equals(Environment.MEDIA_SHARED)) { RuntimeException e = new RuntimeException( "ODK reports :: SDCard error: " + Environment.getExternalStorageState()); throw e; } String[] dirs = { FABARISODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH }; // String[] dirs_Ext = {FABARISODK_ROOT_Ext, FORMS_PATH_Ext, INSTANCES_PATH_Ext, CACHE_PATH_Ext, METADATA_PATH_Ext}; for (String dirName : dirs) { File dir = new File(dirName); if (!dir.exists()) { if (!dir.mkdirs()) { RuntimeException e = new RuntimeException("ODK reports :: Cannot create directory: " + dirName); throw e; } } else { if (!dir.isDirectory()) { RuntimeException e = new RuntimeException( "ODK reports :: " + dirName + " exists, but is not a directory"); throw e; } } } }
From source file:de.fmaul.android.cmis.utils.StorageUtils.java
public static File getStorageFile(Application app, String saveFolder, String filename) throws StorageException { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { StringBuilder builder = new StringBuilder(); builder.append(saveFolder);/*from w w w . java2 s.co m*/ builder.append("/"); builder.append(ROOT_FOLDER_APP); builder.append("/"); builder.append(((CmisApp) app).getRepository().getServer().getName()); if (filename != null) { builder.append("/"); builder.append(filename); } return new File(builder.toString()); } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { throw new StorageException("Storage in Read Only Mode"); } else { throw new StorageException("Storage is unavailable"); } }