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:ch.ethz.dcg.jukefox.commons.utils.AndroidUtils.java
public static boolean isSdCardOk() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { Log.w(TAG, "Access to sd-card is read only"); return false; } else {/*from w ww . ja va 2s. c o m*/ return false; } }
From source file:org.mariotaku.harmony.activity.MusicBrowserActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setVolumeControlStream(AudioManager.STREAM_MUSIC); mImageLoader = HarmonyApplication.getInstance(this).getImageLoaderWrapper(); mActionBar = getActionBar();//from w w w. ja va 2 s. com mActionBar.setDisplayShowTitleEnabled(false); //mActionBar.setDisplayShowHomeEnabled(false); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mPrefs = new PreferencesEditor(this); final 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(); } setContentView(R.layout.music_browser); mSpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, android.R.id.text1); mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mActionBar.setDisplayShowCustomEnabled(true); //mActionBar.setDisplayShowHomeEnabled(true); //mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); //mActionBar.setListNavigationCallbacks(mSpinnerAdapter, this); mActionBar.setCustomView(R.layout.music_browser_control_bar); mControlContainer = mActionBar.getCustomView(); //mViewPager.setEnabled(false); mAlbumArt = (AlbumArtView) mControlContainer.findViewById(R.id.album_art); mTrackName = (TextView) mControlContainer.findViewById(R.id.track_name); mTrackDetail = (TextView) mControlContainer.findViewById(R.id.track_detail); mPlayPauseButton = (ImageButton) mControlContainer.findViewById(R.id.play_pause); mNextButton = (ImageButton) mControlContainer.findViewById(R.id.next); mTabsAdapter = new TabsAdapter(this); mViewPager.setOnPageChangeListener(this); mViewPager.setOffscreenPageLimit(3); mViewPager.setAdapter(mTabsAdapter); mPlayPauseButton.setOnClickListener(this); mNextButton.setOnClickListener(this); configureTabs(!mViewPager.isEnabled()); final int currenttab = mPrefs.getIntState(STATE_KEY_PAGE_POSITION_BROWSER, 0); mActionBar.setSelectedNavigationItem(currenttab); }
From source file:com.kynetx.api.java
private boolean isReadable() { boolean mExternalStorageAvailable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; }//from w ww .jav a 2s . co m return mExternalStorageAvailable; }
From source file:de.petermoesenthin.alarming.util.FileUtil.java
/** * Checks if the external storage is readable * * @return/*from ww w.j ava 2s . c o m*/ */ public static boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; }
From source file:com.hiqes.android.demopermissionsm.ui.EchoFragment.java
private void startDiskLogger() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) || Environment.MEDIA_MOUNTED.equals(state)) { Logger.d(TAG, "External storage available: " + state); File extDir = new File(Environment.getExternalStorageDirectory(), LogLoadDialog.PROG_SAVE_DIR_NAME); if (!extDir.exists()) { if (!extDir.mkdir()) { String errMsg = getString(R.string.err_unable_to_mkdir); Logger.e(TAG, errMsg); Toast.makeText(getContext(), errMsg, Toast.LENGTH_LONG).show(); mSaveProgLog.setChecked(false); return; }/*from ww w . j av a2 s. c o m*/ } try { mDiskLogWriter = new DiskLogWriter(extDir); Logger.registerWriter(mDiskLogWriter); Logger.d(TAG, "Added disk logger"); } catch (IOException e) { String errMsg = getString(R.string.err_unable_to_create_log); Logger.e(TAG, errMsg); Toast.makeText(getContext(), errMsg, Toast.LENGTH_LONG).show(); mSaveProgLog.setChecked(false); } } }
From source file:org.godotengine.godot.Utils.java
public static boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; }/*from w w w . jav a 2 s .co m*/ return false; }
From source file:com.lvfq.rabbit.fragment.SettingFragment.java
private boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; }/* w w w . j av a 2 s.c o m*/ return false; }
From source file:com.c4mprod.utils.ImageDownloader.java
/** * Download the specified image from the Internet and binds it to the provided ImageView. The * binding is immediate if the image is found in the cache and will be done asynchronously * otherwise. A null bitmap will be associated to the ImageView if an error occurs. * //from w ww. j av a 2 s . c om * @param url * @param imageView * @param subfolder * the subfolder in sdcard cache * */ public void download(String url, ImageView imageView, String subfolder) { if (subfolder != null) { mSubfolder = "/" + subfolder; } else { mSubfolder = ""; } mfolder = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + imageView.getContext().getPackageName() + "/files/images" + mSubfolder; if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true; try { (new File(mfolder)).mkdirs(); (new File(mfolder + "/.nomedia")).createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false; } 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 = mExternalStorageWriteable = false; } resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { forceDownload(url, imageView); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); imageView.setBackgroundDrawable(null); if (listener != null) { listener.onImageDownloaded(imageView, url, mfolder + "/" + URLEncoder.encode(url), imageView.getDrawable().getIntrinsicWidth(), imageView.getDrawable().getIntrinsicWidth()); } } }
From source file:de.fmaul.android.cmis.utils.StorageUtils.java
public static File getStorageFile(Application app, String repoId, String storageType, String itemId, String filename) throws StorageException { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { StringBuilder builder = new StringBuilder(); builder.append(Environment.getExternalStorageDirectory()); builder.append("/"); builder.append("Android"); builder.append("/"); builder.append("data"); builder.append("/"); builder.append(app.getPackageName()); builder.append("/"); if (storageType != null) { builder.append("/"); builder.append(storageType); }// w ww.jav a 2 s .c om if (repoId != null) { builder.append("/"); builder.append(repoId); } if (itemId != null) { builder.append("/"); builder.append(itemId.replaceAll(":", "_")); } 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"); } }
From source file:com.raspi.chatapp.util.storage.file.LocalStorageProvider.java
@Override public Cursor queryRoots(final String[] projection) throws FileNotFoundException { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (getContext() == null || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { return null; }/* w ww. j ava 2 s . co m*/ // Create a cursor with either the requested fields, or the default projection if "projection" is null. final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION); // Add Home directory File homeDir = Environment.getExternalStorageDirectory(); if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, homeDir.getAbsolutePath()); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.home)); row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD); row.add(Root.COLUMN_ICON, R.mipmap.ic_launcher); // These columns are optional row.add(Root.COLUMN_SUMMARY, homeDir.getAbsolutePath()); row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(homeDir.getAbsolutePath()).getAvailableBytes()); // Root.COLUMN_MIME_TYPE is another optional column and useful if you have multiple roots with different // types of mime types (roots that don't match the requested mime type are automatically hidden) } // Add SD card directory File sdCard = new File("/storage/extSdCard"); String storageState = EnvironmentCompat.getStorageState(sdCard); if (TextUtils.equals(storageState, Environment.MEDIA_MOUNTED) || TextUtils.equals(storageState, Environment.MEDIA_MOUNTED_READ_ONLY)) { final MatrixCursor.RowBuilder row = result.newRow(); // These columns are required row.add(Root.COLUMN_ROOT_ID, sdCard.getAbsolutePath()); row.add(Root.COLUMN_DOCUMENT_ID, sdCard.getAbsolutePath()); row.add(Root.COLUMN_TITLE, getContext().getString(R.string.sd_card)); // Always assume SD Card is read-only row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY); row.add(Root.COLUMN_ICON, R.drawable.ic_sd_card); row.add(Root.COLUMN_SUMMARY, sdCard.getAbsolutePath()); row.add(Root.COLUMN_AVAILABLE_BYTES, new StatFs(sdCard.getAbsolutePath()).getAvailableBytes()); } return result; } else return null; }