android.os.Environment#getExternalStorageState ( )源码实例Demo

下面列出了android.os.Environment#getExternalStorageState ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: reader   文件: DirectoryManager.java
/**
 * 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;
}
 
源代码2 项目: PictureSelector   文件: MediaUtils.java
/**
 * 创建一条图片地址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];
}
 
源代码3 项目: HttpRequest   文件: JkChatActivity.java
/**
 * 拍照
 * @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();
    }
}
 
源代码4 项目: SprintNBA   文件: StorageUtils.java
/**
 * 获取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;
}
 
源代码5 项目: android_dbinspector   文件: DatabaseHelper.java
/**
 * @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;
}
 
源代码6 项目: FaceRecognitionApp   文件: TinyDB.java
/**
 * 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);
}
 
源代码7 项目: VideoOS-Android-SDK   文件: VenvyDeviceUtil.java
public static boolean existSDcard() {
    String externalStorageState;
    try {
        externalStorageState = Environment.getExternalStorageState();
    } catch (NullPointerException e) { // (sh)it happens (Issue #660)
        externalStorageState = "";
    }
    return MEDIA_MOUNTED.equals(externalStorageState);
}
 
源代码8 项目: droidddle   文件: ImageManager.java
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;
}
 
源代码9 项目: medialibrary   文件: GalleryUtils.java
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;
}
 
源代码10 项目: faceswap   文件: UIUtils.java
private static boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}
 
源代码11 项目: Neptune   文件: PluginInstaller.java
/**
 * 获取插件安装目录,内置目录或者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);
}
 
源代码12 项目: IdealMedia   文件: FileUtils.java
/**
 * @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;

}
 
源代码13 项目: MiBandDecompiled   文件: c.java
public static boolean a()
{
    String s = Environment.getExternalStorageState();
    return "mounted".equals(s) || "mounted_ro".equals(s);
}
 
源代码14 项目: Kandroid   文件: TaskDetailActivity.java
@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);
    }
}
 
源代码15 项目: letv   文件: LetvTools.java
public static boolean sdCardMounted() {
    String state = Environment.getExternalStorageState();
    return state.equals("mounted") && !state.equals("mounted_ro");
}
 
源代码16 项目: PowerFileExplorer   文件: LibraryActivity.java
protected boolean isExternalStorageReadable() {
	String state = Environment.getExternalStorageState();
	if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state))
		return true;
	return false;
}
 
public static boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state) ||
            Environment.MEDIA_MOUNTED_READ_ONLY.equals(state);
}
 
源代码18 项目: buffer_bci   文件: AlphaLatContClassifierThread.java
public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state);
}
 
源代码19 项目: osmdroid   文件: StorageUtils.java
/**
 * @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);
}
 
源代码20 项目: Clip-Stack   文件: BackupExport.java
private static boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state);
}