Java Code Examples for android.os.Environment#getExternalStorageState()
The following examples show how to use
android.os.Environment#getExternalStorageState() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectoryManager.java From reader with MIT License | 9 votes |
/** * Determine if SD card exists. * * @return T=exists, F=not found */ public static boolean testSaveLocationExists() { String sDCardStatus = Environment.getExternalStorageState(); boolean status; // If SD card is mounted if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) { status = true; } // If no SD card else { status = false; } return status; }
Example 2
Source File: MediaUtils.java From PictureSelector with Apache License 2.0 | 6 votes |
/** * 创建一条图片地址uri,用于保存拍照后的照片 * * @param context * @param suffixType * @return 图片的uri */ @Nullable public static Uri createImageUri(final Context context, String suffixType) { final Uri[] imageFilePath = {null}; String status = Environment.getExternalStorageState(); String time = ValueOf.toString(System.currentTimeMillis()); // ContentValues是我们希望这条记录被创建时包含的数据信息 ContentValues values = new ContentValues(3); values.put(MediaStore.Images.Media.DISPLAY_NAME, DateUtils.getCreateFileName("IMG_")); values.put(MediaStore.Images.Media.DATE_TAKEN, time); values.put(MediaStore.Images.Media.MIME_TYPE, TextUtils.isEmpty(suffixType) ? PictureMimeType.MIME_TYPE_IMAGE : suffixType); // 判断是否有SD卡,优先使用SD卡存储,当没有SD卡时使用手机存储 if (status.equals(Environment.MEDIA_MOUNTED)) { values.put(MediaStore.Images.Media.RELATIVE_PATH, PictureMimeType.DCIM); imageFilePath[0] = context.getContentResolver() .insert(MediaStore.Images.Media.getContentUri("external"), values); } else { imageFilePath[0] = context.getContentResolver() .insert(MediaStore.Images.Media.getContentUri("internal"), values); } return imageFilePath[0]; }
Example 3
Source File: JkChatActivity.java From HttpRequest with Apache License 2.0 | 6 votes |
/** * 拍照 * @author leibing * @createTime 2017/5/16 * @lastModify 2017/5/16 * @param * @return */ private void takePhotos() { if (connectStatus == PROMPT_LINE_TIP_ONE_STATUS || connectStatus == PROMPT_LINE_TIP_THREE_STATUS || connectStatus == PROMPT_LINE_TIP_FOUR_STATUS){ ToastUtils.show(JkChatActivity.this, JK_CHAT_DISCONNECT_TIP); return; } // 判断SD卡是否存在 String SDState = Environment.getExternalStorageState(); if (SDState.equals(Environment.MEDIA_MOUNTED)) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); ContentValues values = new ContentValues(); // 使用照相机拍照,拍照后的图片会存放在相册中。使用这种方式好处就是:获取的图片是拍照后的原图, // 如果不实用ContentValues存放照片路径的话,拍照后获取的图片为缩略图有可能不清晰 photoUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(intent, TAKE_PHOTO_CODE); } else { Toast.makeText(this, SDCARD_NO_EXIST, Toast.LENGTH_LONG).show(); } }
Example 4
Source File: DatabaseHelper.java From android_dbinspector with Apache License 2.0 | 6 votes |
/** * @return true if External Storage Present */ private static boolean isExternalAvailable() { boolean externalStorageAvailable = false; String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media externalStorageAvailable = true; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media externalStorageAvailable = true; } 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 externalStorageAvailable = false; } return externalStorageAvailable; }
Example 5
Source File: StorageUtils.java From SprintNBA with Apache License 2.0 | 6 votes |
/** * 获取SD卡信息 * * @return */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static SDCardInfo getSDCardInfo() { SDCardInfo sd = new SDCardInfo(); String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { sd.isExist = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { File sdcardDir = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(sdcardDir.getPath()); sd.totalBlocks = sf.getBlockCountLong(); sd.blockByteSize = sf.getBlockSizeLong(); sd.availableBlocks = sf.getAvailableBlocksLong(); sd.availableBytes = sf.getAvailableBytes(); sd.freeBlocks = sf.getFreeBlocksLong(); sd.freeBytes = sf.getFreeBytes(); sd.totalBytes = sf.getTotalBytes(); } } LogUtils.i(TAG, sd.toString()); return sd; }
Example 6
Source File: TinyDB.java From FaceRecognitionApp with GNU General Public License v2.0 | 5 votes |
/** * Check if external storage is readable or not * @return true if readable, false otherwise */ public static boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state); }
Example 7
Source File: FileUtils.java From IdealMedia with Apache License 2.0 | 5 votes |
/** * @return True if the external storage is writable. False otherwise. */ public static boolean isWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; }
Example 8
Source File: PluginInstaller.java From Neptune with Apache License 2.0 | 5 votes |
/** * 获取插件安装目录,内置目录或者SD卡目录 * 目前VR插件是安装在SD的/Android/data目录的 */ private static File getPreferredInstallLocation(Context context, PackageInfo pkgInfo, String apkName) { int installLocation = ReflectionUtils.on(pkgInfo).<Integer>get("installLocation"); PluginDebugLog.installFormatLog(TAG, "plugin apk %s, installLocation: %s,", apkName, installLocation); // see PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL final int INSTALL_LOCATION_PREFER_EXTERNAL = 2; boolean preferExternal = installLocation == INSTALL_LOCATION_PREFER_EXTERNAL; // 查看外部存储器是否可用 if (preferExternal) { String state = Environment.getExternalStorageState(); if (!Environment.MEDIA_MOUNTED.equals(state)) { // 不可用 preferExternal = false; } } if (preferExternal) { // 尝试安装到外部存储器 File externalDir = context.getExternalFilesDir(PluginInstaller.PLUGIN_ROOT_PATH); if (externalDir != null && externalDir.exists()) { File destFile = new File(externalDir, apkName); PluginDebugLog.installFormatLog(TAG, "install to Location %s", destFile.getPath()); return destFile; } } // 返回默认安装位置 return getDefaultInstallLocation(context, apkName); }
Example 9
Source File: UIUtils.java From faceswap with Apache License 2.0 | 5 votes |
private static boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { return true; } return false; }
Example 10
Source File: GalleryUtils.java From medialibrary with Apache License 2.0 | 5 votes |
public static boolean hasSpaceForSize(long size) { String state = Environment.getExternalStorageState(); if (!Environment.MEDIA_MOUNTED.equals(state)) { return false; } String path = Environment.getExternalStorageDirectory().getPath(); try { StatFs stat = new StatFs(path); return stat.getAvailableBlocks() * (long) stat.getBlockSize() > size; } catch (Exception e) { Log.i(TAG, "Fail to access external storage", e); } return false; }
Example 11
Source File: ImageManager.java From droidddle with Apache License 2.0 | 5 votes |
public static boolean hasStorage(boolean requireWriteAccess) { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { if (requireWriteAccess) { boolean writable = checkFsWritable(); return writable; } else { return true; } } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { return true; } return false; }
Example 12
Source File: VenvyDeviceUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
public static boolean existSDcard() { String externalStorageState; try { externalStorageState = Environment.getExternalStorageState(); } catch (NullPointerException e) { // (sh)it happens (Issue #660) externalStorageState = ""; } return MEDIA_MOUNTED.equals(externalStorageState); }
Example 13
Source File: ImageImportActivity.java From android-storage-permissions with Apache License 2.0 | 4 votes |
public static boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state); }
Example 14
Source File: AlphaLatContClassifierThread.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
public boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state); }
Example 15
Source File: LibraryActivity.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
protected boolean isExternalStorageReadable() { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) return true; return false; }
Example 16
Source File: StorageUtils.java From osmdroid with Apache License 2.0 | 4 votes |
/** * @return True if the primary shared storage is writable. False otherwise. * @deprecated As of 6.1.7, will be removed in the future. */ @Deprecated public static boolean isWritable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state); }
Example 17
Source File: LetvTools.java From letv with Apache License 2.0 | 4 votes |
public static boolean sdCardMounted() { String state = Environment.getExternalStorageState(); return state.equals("mounted") && !state.equals("mounted_ro"); }
Example 18
Source File: BackupExport.java From Clip-Stack with MIT License | 4 votes |
private static boolean isExternalStorageWritable() { String state = Environment.getExternalStorageState(); return Environment.MEDIA_MOUNTED.equals(state); }
Example 19
Source File: TaskDetailActivity.java From Kandroid with GNU General Public License v3.0 | 4 votes |
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.action_edit_comment: showCommentDialog((KanboardComment)commentListview.getAdapter().getItem(info.position)); return true; case R.id.action_delete_comment: showDeleteCommentDialog((KanboardComment)commentListview.getAdapter().getItem(info.position)); return true; case R.id.action_edit_subtask: showSubtaskDialog((KanboardSubtask)subtaskListview.getAdapter().getItem(info.position)); return super.onContextItemSelected(item); case R.id.action_delete_subtask: showDeleteSubtaskDialog((KanboardSubtask)subtaskListview.getAdapter().getItem(info.position)); return true; case R.id.action_download_file: String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { downloadFileId = ((KanboardTaskFile) filesListview.getAdapter().getItem(info.position)).getId(); downloadFileName = ((KanboardTaskFile) filesListview.getAdapter().getItem(info.position)).getName(); if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Intent downloadIntent = new Intent(this, DownloadIntentService.class); downloadIntent.putExtra("request", KanboardRequest.downloadTaskFile(downloadFileId).JSON[0]); downloadIntent.putExtra("filename", downloadFileName); startService(downloadIntent); } else { ActivityCompat.requestPermissions((Activity) self, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Constants.RequestStoragePermission); } } else { Snackbar.make(findViewById(R.id.root_layout), getString(R.string.error_no_sdcard), Snackbar.LENGTH_LONG).show(); } return true; case R.id.action_delete_file: showDeleteTaskFileDialog((KanboardTaskFile) filesListview.getAdapter().getItem(info.position)); return true; default: return super.onContextItemSelected(item); } }
Example 20
Source File: c.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
public static boolean a() { String s = Environment.getExternalStorageState(); return "mounted".equals(s) || "mounted_ro".equals(s); }