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:org.osm.keypadmapper2.KeypadMapper2Activity.java
/** Called when the activity is first created. */ @Override/*from www .ja v a2 s .c o m*/ public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "create"); if (KeypadMapperApplication.getInstance().getSettings().isLayoutOptimizationEnabled()) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); uiOptimizationEnabled = true; } super.onCreate(savedInstanceState); if (KeypadMapperApplication.getInstance().getSettings().isCompassAvailable()) { sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); gsensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); msensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); } updateLocale(); setContentView(R.layout.main); menu = new KeypadMapperMenu(findViewById(R.id.menu)); menu.setMenuListener(this); gestureDetector = new GestureDetector(this, new MyGestureDetector()); // check for external storage String extStorageState = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(extStorageState)) { // We can read and write the media } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) { // We can only read the media showDialogFatalError(localizer.getString("errorStorageRO")); } 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 showDialogFatalError(localizer.getString("errorStorageUnavailable")); } File kpmFolder = KeypadMapperApplication.getInstance().getKeypadMapperDirectory(); if (!kpmFolder.exists()) { if (!kpmFolder.mkdir()) { showDialogFatalError(localizer.getString("FolderCreationFailed")); } } if (savedInstanceState == null) { savedInstanceState = getIntent().getExtras(); } duplicates = new StringBuffer(); allData = new StringBuffer(); if (savedInstanceState == null) { // first start state = State.keypad; // only on first run automatically start GPS recording if (KeypadMapperApplication.getInstance().getSettings().isFirstRun()) { KeypadMapperApplication.getInstance().getSettings().clearFirstRun(); KeypadMapperApplication.getInstance().startGpsRecording(); // always start when app starts } } else { // restart state = State.values()[savedInstanceState.getInt("state", State.keypad.ordinal())]; satteliteInfoVisible = savedInstanceState.getBoolean("sat_info"); extendedAddressActive = savedInstanceState.getBoolean("extended_address"); if (savedInstanceState.getBoolean("debug_dialog_on")) { duplicates.append(savedInstanceState.getString("duplicates")); allData.append(savedInstanceState.getString("allData")); showTestScreenDialog(); } } keypadFragment = (KeypadFragment) getSupportFragmentManager().findFragmentByTag("keypad"); Log.d("Keypad", "isTablet = " + getResources().getBoolean(R.bool.is_tablet)); if (!getResources().getBoolean(R.bool.is_tablet)) { extendedAddressFragment = (ExtendedAddressFragment) getSupportFragmentManager() .findFragmentByTag("extended_address"); } else { extendedAddressFragment = (ExtendedAddressFragment) getSupportFragmentManager() .findFragmentById(R.id.fragment_extended_address_tablet); } Log.d("Keypad", "extended address fragment = " + extendedAddressFragment); satelliteInfo = (SatelliteInfoFragment) getSupportFragmentManager().findFragmentByTag("satellite"); satInfoView = findViewById(R.id.satellite_view); extendedAddressView = findViewById(R.id.extended_address_view); keypadView = findViewById(R.id.keypad_view); if (keypadView == null && extendedAddressView == null) { state = State.both; } btnTestVersion = (Button) keypadView.findViewById(R.id.btnTestVersion); /* btnTestVersion.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(); i.setClass(KeypadMapper2Activity.this, SettingsActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i); // show debug screen with all registered addresses and locations //showTestScreenDialog(); } });*/ if (satteliteInfoVisible) { showSatteliteInfo(); } else { showKeypad(); } locationProvider.refreshReferenceToGps(); }
From source file:es.rgmf.libresportgps.MainActivity.java
/** * Check if external storage is available. If SD is not available then it * shows a message./*from ww w .j a v a2 s .c o m*/ */ private void checkExternalStorage() { String state = Environment.getExternalStorageState(); if (!Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { Toast.makeText(this, R.string.external_storage_not_available, Toast.LENGTH_SHORT).show(); } }
From source file:com.bamobile.fdtks.util.Tools.java
public static boolean isSdReadable() { boolean mExternalStorageAvailable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = true; Log.i("isSdReadable", "External storage card is readable."); } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media Log.i("isSdReadable", "External storage card is readable."); mExternalStorageAvailable = true; } else {// w ww . j a v a 2 s . c om // 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 = false; } return mExternalStorageAvailable; }
From source file:it.iziozi.iziozi.gui.IOBoardFragment.java
public boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; }//from ww w .j av a2s. com return false; }
From source file:com.stylovid.fastbattery.LogViewFragment.java
private void exportCSV() { if (ContextCompat.checkSelfPermission(getActivity(), P_WRITE_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[] { P_WRITE_STORAGE }, BatteryInfoActivity.PR_LVF_WRITE_STORAGE); return;//from www . ja va2s .c om } String state = Environment.getExternalStorageState(); if (state != null && state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { Toast.makeText(getActivity(), pfrag.str.read_only_storage, Toast.LENGTH_SHORT).show(); return; } else if (state == null || !state.equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(getActivity(), pfrag.str.inaccessible_w_reason + state, Toast.LENGTH_SHORT).show(); return; } Date d = new Date(); String csvFileName = "FastBattery-Logs-" + d.getTime() + ".csv"; File root = Environment.getExternalStorageDirectory(); File csvFile = new File(root, csvFileName); String[] csvFields = { pfrag.str.date, pfrag.str.time, pfrag.str.status, pfrag.str.charge, pfrag.str.temperature, pfrag.str.temperature_f, pfrag.str.voltage }; try { if (!csvFile.createNewFile() || !csvFile.canWrite()) { Toast.makeText(getActivity(), pfrag.str.inaccessible_storage, Toast.LENGTH_SHORT).show(); return; } BufferedWriter buf = new BufferedWriter(new FileWriter(csvFile)); int cols = csvFields.length; int i; for (i = 0; i < cols; i++) { buf.write(csvFields[i]); if (i != cols - 1) buf.write(","); } buf.write("\r\n"); int statusCode; int[] statusCodes; int status, plugged, status_age; String s; for (completeCursor.moveToFirst(); !completeCursor.isAfterLast(); completeCursor.moveToNext()) { cols = CSV_ORDER.length; for (i = 0; i < cols; i++) { if (CSV_ORDER[i].equals(LogDatabase.KEY_TIME)) { d.setTime(completeCursor.getLong(mAdapter.timeIndex)); buf.write(mAdapter.dateFormat.format(d) + "," + mAdapter.timeFormat.format(d) + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_STATUS_CODE)) { statusCode = completeCursor.getInt(mAdapter.statusCodeIndex); statusCodes = LogDatabase.decodeStatus(statusCode); status = statusCodes[0]; plugged = statusCodes[1]; status_age = statusCodes[2]; if (status == LogDatabase.STATUS_BOOT_COMPLETED) s = pfrag.str.status_boot_completed; else if (status_age == LogDatabase.STATUS_OLD) s = pfrag.str.log_statuses_old[status]; else s = pfrag.str.log_statuses[status]; if (plugged > 0) s += " " + pfrag.str.pluggeds[plugged]; buf.write(s + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_CHARGE)) { buf.write(String.valueOf(completeCursor.getInt(mAdapter.chargeIndex)) + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_TEMPERATURE)) { int temperature = completeCursor.getInt(mAdapter.temperatureIndex); buf.write(String.valueOf(temperature / 10.0) + ","); buf.write(String.valueOf(java.lang.Math.round(temperature * 9 / 5.0) / 10.0 + 32.0) + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_VOLTAGE)) { buf.write(String.valueOf(completeCursor.getInt(mAdapter.voltageIndex) / 1000.0)); } } buf.write("\r\n"); } buf.close(); } catch (Exception e) { Toast.makeText(getActivity(), pfrag.str.inaccessible_storage, Toast.LENGTH_SHORT).show(); return; } Toast.makeText(getActivity(), pfrag.str.file_written, Toast.LENGTH_SHORT).show(); }
From source file:com.uberspot.storageutils.StorageUtils.java
/** @param requireWriteAccess boolean indicating that write access to external storage is required * @return true if the device has external storage. If requireWriteAccess is set to true it will also check * for write permissions on the external storage. If the media isn't mounted or it is mounted as read-only * when writeAccess is required it returns false. */// ww w .j a v a 2 s . co m public static boolean hasExternalStorage(boolean requireWriteAccess) { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; }
From source file:com.darshancomputing.BatteryIndicatorPro.LogViewFragment.java
private void exportCSV() { String state = Environment.getExternalStorageState(); if (state != null && state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { Toast.makeText(activity.context, activity.str.read_only_storage, Toast.LENGTH_SHORT).show(); return;//w w w. j a v a 2s.c om } else if (state == null || !state.equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(activity.context, activity.str.inaccessible_w_reason + state, Toast.LENGTH_SHORT).show(); return; } Date d = new Date(); String csvFileName = "BatteryIndicatorPro-Logs-" + d.getTime() + ".csv"; File root = Environment.getExternalStorageDirectory(); File csvFile = new File(root, csvFileName); String[] csvFields = { activity.str.date, activity.str.time, activity.str.status, activity.str.charge, activity.str.temperature, activity.str.temperature_f, activity.str.voltage }; try { if (!csvFile.createNewFile() || !csvFile.canWrite()) { Toast.makeText(activity.context, activity.str.inaccessible_storage, Toast.LENGTH_SHORT).show(); return; } BufferedWriter buf = new BufferedWriter(new FileWriter(csvFile)); int cols = csvFields.length; int i; for (i = 0; i < cols; i++) { buf.write(csvFields[i]); if (i != cols - 1) buf.write(","); } buf.write("\r\n"); int statusCode; int[] statusCodes; int status, plugged, status_age; String s; for (completeCursor.moveToFirst(); !completeCursor.isAfterLast(); completeCursor.moveToNext()) { cols = CSV_ORDER.length; for (i = 0; i < cols; i++) { if (CSV_ORDER[i].equals(LogDatabase.KEY_TIME)) { d.setTime(completeCursor.getLong(mAdapter.timeIndex)); buf.write(mAdapter.dateFormat.format(d) + "," + mAdapter.timeFormat.format(d) + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_STATUS_CODE)) { statusCode = completeCursor.getInt(mAdapter.statusCodeIndex); statusCodes = LogDatabase.decodeStatus(statusCode); status = statusCodes[0]; plugged = statusCodes[1]; status_age = statusCodes[2]; if (status_age == LogDatabase.STATUS_OLD) s = activity.str.log_statuses_old[status]; else s = activity.str.log_statuses[status]; if (plugged > 0) s += " " + activity.str.pluggeds[plugged]; buf.write(s + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_CHARGE)) { buf.write(String.valueOf(completeCursor.getInt(mAdapter.chargeIndex)) + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_TEMPERATURE)) { int temperature = completeCursor.getInt(mAdapter.temperatureIndex); buf.write(String.valueOf(temperature / 10.0) + ","); buf.write(String.valueOf(java.lang.Math.round(temperature * 9 / 5.0) / 10.0 + 32.0) + ","); } else if (CSV_ORDER[i].equals(LogDatabase.KEY_VOLTAGE)) { buf.write(String.valueOf(completeCursor.getInt(mAdapter.voltageIndex) / 1000.0)); } } buf.write("\r\n"); } buf.close(); } catch (Exception e) { Toast.makeText(activity.context, activity.str.inaccessible_storage, Toast.LENGTH_SHORT).show(); return; } Toast.makeText(activity.context, activity.str.file_written, Toast.LENGTH_SHORT).show(); }
From source file:io.github.silencio_app.silencio.MainActivity.java
public boolean isExternalReadable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state); }
From source file:com.httrack.android.HTTrackActivity.java
private void warnIfExternalStorageUnsuitable() { String message;//from www . j a va 2s.c o m final String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { final File root = getProjectRootFile(); if (root == null) { message = getString(R.string.could_not_get_external_directory); } else if (!root.exists()) { message = getString(R.string.could_not_write_to) + " " + root.getAbsolutePath(); } else { return; } } else { if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { message = getString(R.string.read_only_storage_media); } else { message = getString(R.string.no_storage_media); } } showNotification(message + "\n" + getString(R.string.may_not_download_until_problem_fixed), true); }
From source file:com.c4mprod.utils.ImageManager.java
private boolean isSDCacheReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } else {//from w w w.j a v a2s . com return false; } }