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.snipme.download.ImageDownloader.java
public static String saveToSdCard(Bitmap bitmap, String filename) { String stored = null;//w ww. ja v a 2 s. com if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { return null; } File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), "SnipMe"); // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { Log.i("DownloadImage", "Create Folder Snipme"); if (!mediaStorageDir.mkdirs()) { Log.d("DownloadImage", "failed to create directory SnipMe"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File file = new File(mediaStorageDir.getPath() + File.separator + filename + "_" + timeStamp + ".png"); //File sdcard = Environment.getExternalStorageDirectory(); //File folder = new File(sdcard.getAbsoluteFile(), "SnipMe");// the // dot // makes // this // directory // hidden // to // the // user //folder.mkdir(); //File file = new File(folder.getAbsoluteFile(), filename + ".png"); if (file.exists()) return stored; try { FileOutputStream out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 90, out); out.flush(); out.close(); stored = "success"; } catch (Exception e) { e.printStackTrace(); } return stored; }
From source file:jahirfiquitiva.iconshowcase.utilities.ZooperIconFontsHelper.java
private Subscription subscription(final int state) { if (state == FIXING) try {//from w w w . jav a 2s.c o m if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) throw new IOException("External Media is not mounted!"); } catch (IOException exception) { if (this.mCallback != null) this.mCallback.OnError(exception); } Observable<?> o = Observable.create(this.onSubscribe(state)).subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()); if (state != CHECKING) o.take(state == FIXING ? this.mMissing.size() : this.mFixed.size() + 1); if (this.mSubscription != null) { this.mSubscription.unsubscribe(); this.mSubscription = null; } return this.mSubscription = o.subscribe(new Observer<Object>() { final ZooperIconFontsHelper c = ZooperIconFontsHelper.this; @Override public void onCompleted() { int s; if (state != CHECKING) s = state == FIXING ? c.mFixIndex : c.mCancelIndex - 1; else s = c.mMissing.size(); if (c.mCheckAndFix && s > 0) c.fix(); if (c.mCallback != null) c.mCallback.OnFinished(state, s); } @Override public void onError(Throwable throwable) { if (c.mCallback != null) c.mCallback.OnError(throwable); } @Override public void onNext(Object object) { if (object instanceof File) { if (c.mCallback != null) c.mCallback.OnSaved((File) object); } else if (object instanceof String && state == CANCELING) { if (c.mCallback != null) c.mCallback.OnDeleted((String) object); } } }); }
From source file:com.lazy.gank.logging.Logcat.java
public static Config defaultConfig() { Builder builder = newBuilder();/*w w w . j a v a 2s. c om*/ // ??? do { String state = Environment.getExternalStorageState(); // SD ? if (!Environment.MEDIA_MOUNTED.equals(state)) { Log.w(TAG, "Not mount SD card!"); break; } // SD ??? if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { Log.w(TAG, "Not allow write SD card!"); break; } File externalCacheDir = mContext.getExternalCacheDir(); // context.getExternalCacheDir() maybe null if (externalCacheDir != null) { builder.logSavePath = externalCacheDir.getAbsolutePath() + FILE_SEPARATOR + DEFAULT_LOG_DIR; } else { Log.e(TAG, "externalCacheDir is null!"); builder.fileLogLevel(OPERATION_BIT); break; } // ? SD ????? // ???? ? SD ? Cache/Log String strSaveLogPath = builder.logSavePath; checkSaveLogPath(strSaveLogPath); } while (false); Config config = new Config(builder); return config; }
From source file:com.sinpo.xnfc.nfc.Util.java
public static boolean initDownPath(String path) { if (Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { File file = new File(path); if (!file.exists()) { file.mkdirs();//from w ww . j av a 2s. c om return true; } } return false; }
From source file:com.game.simple.Game3.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (Session.getActiveSession() != null) Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); ////////////////////image//////////////////// if (resultCode != RESULT_OK) { return;//from w w w .j a va 2 s. c om } switch (requestCode) { case PICK_FROM_FILE: if (data == null) { Log.e("PICK_FROM_FILE", "NULL"); return; } selectedImage = data.getData(); cropImage(selectedImage); break; case PIC_CROP: if (data == null) { return; } Bundle extras = data.getExtras(); Bitmap thePic = extras.getParcelable("data"); Boolean isSDPresent = android.os.Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_MOUNTED); if (isSDPresent) { cropedImagePath = Environment.getExternalStorageDirectory().toString() + "/DCIM/avatar.jpeg"; } else { cropedImagePath = "mnt/emmc/avata.jpeg"; } Log.e("---------------path", cropedImagePath); FileOutputStream out = null; try { out = new FileOutputStream(cropedImagePath); thePic.compress(Bitmap.CompressFormat.JPEG, 90, out); } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (Throwable ignore) { } } break; case CAMERA_CAPTURE: cameraImage = data.getData(); if (cameraImage == null) { Log.e("CAMERA_CAPTURE", "NULL"); return; } cropImage(cameraImage); break; default: break; } }
From source file:com.android.fastlibrary.AppException.java
/** * ?//www.j a v a 2 s . c om * * @param excp */ public void saveErrorLog(Exception excp) { String errorlog = "errorlog.txt"; String savePath = ""; String logFilePath = ""; FileWriter fw = null; PrintWriter pw = null; try { //?SD? String storageState = Environment.getExternalStorageState(); if (storageState.equals(Environment.MEDIA_MOUNTED)) { savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/OSChina/Log/"; File file = new File(savePath); if (!file.exists()) { file.mkdirs(); } logFilePath = savePath + errorlog; } //SD? if (logFilePath == "") { return; } File logFile = new File(logFilePath); if (!logFile.exists()) { logFile.createNewFile(); } fw = new FileWriter(logFile, true); pw = new PrintWriter(fw); pw.println("--------------------" + (new Date().toLocaleString()) + "---------------------"); excp.printStackTrace(pw); pw.close(); fw.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (pw != null) { pw.close(); } if (fw != null) { try { fw.close(); } catch (IOException e) { } } } }
From source file:net.peterkuterna.android.apps.devoxxfrsched.util.ImageDownloader.java
Bitmap downloadBitmap(String url) { final int IO_BUFFER_SIZE = 4 * 1024; File cacheFile = null;//from w ww. ja va2s . c o m try { MessageDigest mDigest = MessageDigest.getInstance("SHA-1"); mDigest.update(url.getBytes()); final String cacheKey = bytesToHexString(mDigest.digest()); if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { cacheFile = new File(Environment.getExternalStorageDirectory() + File.separator + "Android" + File.separator + "data" + File.separator + mContext.getPackageName() + File.separator + "cache" + File.separator + "bitmap_" + cacheKey + ".tmp"); } } catch (NoSuchAlgorithmException e) { // Oh well, SHA-1 not available (weird), don't cache bitmaps. } HttpGet getRequest = null; try { getRequest = new HttpGet(url); } catch (IllegalArgumentException e) { Log.e(TAG, "Error while constructing get request: " + e.getMessage()); return null; } try { HttpResponse response = mClient.execute(getRequest); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url); return null; } final HttpEntity entity = response.getEntity(); if (entity != null) { final byte[] respBytes = EntityUtils.toByteArray(entity); if (cacheFile != null) { try { cacheFile.getParentFile().mkdirs(); cacheFile.createNewFile(); FileOutputStream fos = new FileOutputStream(cacheFile); fos.write(respBytes); fos.close(); } catch (FileNotFoundException e) { Log.w(TAG, "Error writing to bitmap cache: " + cacheFile.toString(), e); } catch (IOException e) { Log.w(TAG, "Error writing to bitmap cache: " + cacheFile.toString(), e); } } return BitmapFactory.decodeByteArray(respBytes, 0, respBytes.length); } } catch (IOException e) { getRequest.abort(); Log.w(TAG, "I/O error while retrieving bitmap from " + url, e); } catch (IllegalStateException e) { getRequest.abort(); Log.w(TAG, "Incorrect URL: " + url); } catch (Exception e) { getRequest.abort(); Log.w(TAG, "Error while retrieving bitmap from " + url, e); } return null; }
From source file:com.android.volley.misc.Utils.java
@SuppressLint("NewApi") private static boolean isExternalMounted() { if (Utils.hasGingerbread()) { return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable(); }//from ww w .j a va 2 s . c om return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); }
From source file:com.momock.util.Logger.java
public static void open(Context context, final String name, int maxLogFiles, int level) { if (!enabled) return;//from w ww .j a v a2 s . c o m appName = context.getPackageName(); logName = name; logFileName = logName + "[" + new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(new Date()) + "].log"; if (logStream == System.out) { File logDir = null; try { if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { logDir = Environment.getExternalStorageDirectory(); } else if (context != null) { logDir = context.getCacheDir(); } if (logDir != null) { android.util.Log.d("Logger", logDir.getAbsolutePath()); String[] fs = logDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return filename.startsWith(logName + "[") && filename.endsWith("].log"); } }); List<String> allLogs = new ArrayList<String>(); for (int i = 0; fs != null && i < fs.length; i++) allLogs.add(fs[i]); Collections.sort(allLogs); for (int i = 0; i < allLogs.size() - maxLogFiles + 1; i++) new File(logDir, allLogs.get(i)).delete(); logStream = new PrintStream(new FileOutputStream(new File(logDir, logFileName), false)); } } catch (IOException e) { android.util.Log.e("Logger", "Fails to create log file!", e); } } logLevel = level; logStream.println("========== Logger Begin =========="); logStream.flush(); }