List of usage examples for android.os Environment MEDIA_MOUNTED
String MEDIA_MOUNTED
To view the source code for android.os Environment MEDIA_MOUNTED.
Click Source Link
From source file:com.androidzeitgeist.dashwatch.common.IOUtil.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static File getBestAvailableFilesRoot(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // In KitKat we can query multiple devices. // TODO: optimize for stability instead of picking first one File[] roots = context.getExternalFilesDirs(null); if (roots != null) { for (File root : roots) { if (root == null) { continue; }//from ww w .ja v a 2 s . c om if (Environment.MEDIA_MOUNTED.equals(Environment.getStorageState(root))) { return root; } } } } else if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { // Pre-KitKat, only one external storage device was addressable return context.getExternalFilesDir(null); } // Worst case, resort to internal storage return context.getFilesDir(); }
From source file:com.example.parking.ParkingInformationActivity.java
private void openTakePhoto() { /**//from ww w . j a va 2 s .c o m * ???sdcard?? */ String state = Environment.getExternalStorageState(); //sdcard???? if (state.equals(Environment.MEDIA_MOUNTED)) { //? Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, TAKE_PHOTO); } else { Toast.makeText(ParkingInformationActivity.this, "sdcard??", Toast.LENGTH_SHORT).show(); } }
From source file:com.zlkj.dingdangwuyou.activity.CompanyInfoActivity.java
/** * ?/* w w w. ja v a 2 s .c om*/ */ private void showAvatarOption() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String[] items = new String[] { "?", "" }; builder.setTitle("").setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(); switch (which) { case 0: // ? if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String curTime = AppTool.dateFormat(System.currentTimeMillis(), "yyyyMMddHHmmss"); // ??? File imagePath = new File(Environment.getExternalStorageDirectory() + Const.APP_IMAGE_PATH); if (!imagePath.exists()) { imagePath.mkdirs(); } cameraFile = new File(imagePath.getPath(), curTime + ".jpg"); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)); startActivityForResult(intent, Const.REQUEST_CODE_CAMERA); } else { Toast.makeText(context, "???", Toast.LENGTH_SHORT) .show(); } break; case 1: // intent.setAction(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, Const.REQUEST_CODE_GALLERY); break; default: break; } } }); builder.show(); }
From source file:com.lge.osclibrary.OSCCommandsExecute.java
/** * Create folder if it doesn't exist//from w w w .ja v a2 s . co m * * @param folderPath path to create folder */ private void createFolder(String folderPath) { String TAG_FOLDER = "CREATE_FOLDER: "; try { //check sdcard mount state String str = Environment.getExternalStorageState(); if (str.equals(Environment.MEDIA_MOUNTED)) { Log.d(TAG, "sdcard mounted"); File file = new File(folderPath); if (!file.exists()) { boolean res = file.mkdirs(); if (!res) { Log.d(TAG, "ERROR: Fail to make directory"); return; } //check result if (file.exists()) Log.e(TAG, TAG_FOLDER + folderPath + " folder created"); else Log.e(TAG, TAG_FOLDER + folderPath + " folder not created"); } else { Log.d(TAG, TAG_FOLDER + folderPath + " is exist"); } } else { Log.d(TAG, TAG_FOLDER + "sdcard unmount, use default image."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:fiskinfoo.no.sintef.fiskinfoo.Implementation.FiskInfoUtility.java
/** * Checks if external storage is available for read and write. * * @return True if external storage is available, false otherwise. */// w w w . j av a 2 s.com public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state); }
From source file:com.trellmor.berrymotes.sync.EmoteDownloader.java
private boolean isStorageAvailable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state); }
From source file:com.synconset.ImageFetcher.java
/** * Save Thumbnail to private storage./*from ww w .j ava 2 s. com*/ */ boolean storeBitmapToPrivate(Integer position, Bitmap bitmap) { if (thumbnails.containsKey(position)) { return true; } /*String state = Environment.getExternalStorageState(); if ( !Environment.MEDIA_MOUNTED.equals(state)) { return false; } */ if (!dir_thumb.isDirectory()) { return false; } String state = Environment.getExternalStorageState(); if (!Environment.MEDIA_MOUNTED.equals(state)) { return false; } File file_thumb; try { file_thumb = File.createTempFile("thumb", null, dir_thumb); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } String url_thumb = file_thumb.getAbsolutePath(); if (!saveBitmapToFileCache(bitmap, file_thumb)) { file_thumb.delete(); return false; } thumbnails.put(position, url_thumb); return true; }
From source file:com.example.android.bluetoothlegatt.BluetoothLeService.java
private boolean writeCacheToFile2() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File sdCardDir = Environment.getExternalStorageDirectory();//?SDCard try {//from w ww. j a va2 s .co m boolean isSame = false; //File saveFile1 = new File(sdCardDir, "ble_byte.txt"); File saveFile2 = new File(sdCardDir, "ble_asci.txt"); //FileOutputStream fout1 = new FileOutputStream(saveFile1, true); FileOutputStream fout2 = new FileOutputStream(saveFile2, true); //FileOutputStream fout1 = openFileOutput("out_byte", MODE_APPEND); //FileOutputStream fout2 = openFileOutput("out_asci", MODE_APPEND); StringBuilder hexBuilder = new StringBuilder(); for (int i = 0; i < cacheData2.size(); i++) { byte[] item = cacheData2.get(i); for (byte byteChar : item) hexBuilder.append(String.format("%02X ", byteChar)); //?? add \n to line end?? hexBuilder.append("\n"); fout2.write(item); } //fout1.write(hexBuilder.toString().getBytes()); fout2.write("\nBinary:\n".getBytes()); fout2.write(hexBuilder.toString().getBytes()); // check with standard cardiochek_ble file. if (mStandardBle == null) { mStandardBle = getStandardFile(); if (mStandardBle != null) mStandardBle = mStandardBle.replaceAll("[\\t\\n\\r]", ""); } if (mStandardBle != null && !mStandardBle.equals("")) { // compare file. String hexStr = hexBuilder.toString(); hexStr = hexStr.replaceAll("[\\t\\n\\r]", ""); if (mStandardBle.equalsIgnoreCase(hexStr)) { fout2.write("\nSAME AS cardiochek_ble\n".getBytes()); Log.i(TAG, "SAME AS cardiochek_ble"); isSame = true; } else { fout2.write("\nDIFF WITH cardiochek_ble\n".getBytes()); Log.i(TAG, "nDIFF WITH cardiochek_ble"); } } else { fout2.write("\nNO cardiochek_ble\n".getBytes()); Log.i(TAG, "NO cardiochek_ble"); } //fout1.write("\n\n".getBytes()); fout2.write("\n\n".getBytes()); //fout1.close(); fout2.close(); return isSame; } catch (Exception e) { Log.e(TAG, "error:" + e); e.printStackTrace(); return false; } } else { Log.e(TAG, "sd card fail!"); } return false; }
From source file:com.manning.androidhacks.hack040.util.DiskLruCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * /*from w w w .j ava 2 s .c o m*/ * @param context * The context to use * @param uniqueName * A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use // external cache dir // otherwise use internal cache dir final String cachePath = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) || !Utils.isExternalStorageRemovable() ? Utils.getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:com.aware.Aware.java
@Override public void onCreate() { super.onCreate(); awareContext = getApplicationContext(); aware_preferences = getSharedPreferences("aware_core_prefs", MODE_PRIVATE); if (aware_preferences.getAll().isEmpty()) { SharedPreferences.Editor editor = aware_preferences.edit(); editor.putInt(PREF_FREQUENCY_WATCHDOG, CONST_FREQUENCY_WATCHDOG); editor.putLong(PREF_LAST_SYNC, 0); editor.putLong(PREF_LAST_UPDATE, 0); editor.commit();/*from w ww . j a v a 2 s. c o m*/ } IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); filter.addDataScheme("file"); awareContext.registerReceiver(storage_BR, filter); filter = new IntentFilter(); filter.addAction(Aware.ACTION_AWARE_CLEAR_DATA); filter.addAction(Aware.ACTION_AWARE_REFRESH); filter.addAction(Aware.ACTION_AWARE_SYNC_DATA); filter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE); awareContext.registerReceiver(aware_BR, filter); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); awareStatusMonitor = new Intent(getApplicationContext(), Aware.class); repeatingIntent = PendingIntent.getService(getApplicationContext(), 0, awareStatusMonitor, 0); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, aware_preferences.getInt(PREF_FREQUENCY_WATCHDOG, 300) * 1000, repeatingIntent); Intent synchronise = new Intent(Aware.ACTION_AWARE_SYNC_DATA); webserviceUploadIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, synchronise, 0); if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { stopSelf(); } else { SharedPreferences prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE); if (prefs.getAll().isEmpty() && Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) { PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE, R.xml.aware_preferences, true); prefs.edit().commit(); //commit changes } else { PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE, R.xml.aware_preferences, false); } Map<String, ?> defaults = prefs.getAll(); for (Map.Entry<String, ?> entry : defaults.entrySet()) { if (Aware.getSetting(getApplicationContext(), entry.getKey()).length() == 0) { Aware.setSetting(getApplicationContext(), entry.getKey(), entry.getValue()); } } if (Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) { UUID uuid = UUID.randomUUID(); Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, uuid.toString()); } DEBUG = Aware.getSetting(awareContext, Aware_Preferences.DEBUG_FLAG).equals("true"); TAG = Aware.getSetting(awareContext, Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(awareContext, Aware_Preferences.DEBUG_TAG) : TAG; get_device_info(); if (Aware.DEBUG) Log.d(TAG, "AWARE framework is created!"); //Fixed: only the client application does a ping to AWARE's server if (getPackageName().equals("com.aware")) { new AsyncPing().execute(); } } }