本文整理汇总了Java中android.os.Environment.getExternalStorageState方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.getExternalStorageState方法的具体用法?Java Environment.getExternalStorageState怎么用?Java Environment.getExternalStorageState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Environment
的用法示例。
在下文中一共展示了Environment.getExternalStorageState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FileUtils
import android.os.Environment; //导入方法依赖的package包/类
private FileUtils() {
String sdcardState = Environment.getExternalStorageState();
//如果没SD卡则放缓存
if (Environment.MEDIA_MOUNTED.equals(sdcardState)) {
BASE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/stickercamera/";
} else {
BASE_PATH = Utils.getContext().getCacheDir().getAbsolutePath();
}
STICKER_BASE_PATH = BASE_PATH + "/stickers/";
}
示例2: RecordVideo
import android.os.Environment; //导入方法依赖的package包/类
/**
* Records a video, then raises the AfterRecoding event.
*/
@SimpleFunction
public void RecordVideo() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
Log.i("CamcorderComponent", "External storage is available and writable");
if (requestCode == 0) {
requestCode = form.registerForActivityResult(this);
}
Intent intent = new Intent(CAMCORDER_INTENT);
container.$context().startActivityForResult(intent, requestCode);
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_READONLY);
} else {
form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_NOT_AVAILABLE);
}
}
示例3: updateMemoryStatus
import android.os.Environment; //导入方法依赖的package包/类
private void updateMemoryStatus() {
String state;
// internal
state = getMemoryStatus(Environment.getDataDirectory(), R.string.txt_memory_state_value);
if (state == null) {
state = getString(R.string.txt_status_unknown);
}
mInternalStateView.setText(state);
// external
state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
state = getMemoryStatus(Environment.getExternalStorageDirectory(), R.string.txt_card_state_value);
if (state == null) {
state = getString(R.string.txt_no_card);
}
} else {
state = getString(R.string.txt_no_card);
}
mCardStateView.setText(state);
}
示例4: getFreeDiskSpace
import android.os.Environment; //导入方法依赖的package包/类
/**
* 计算SD卡的剩余空间
* @return 返回-1,说明没有安装sd卡
*/
public static long getFreeDiskSpace() {
String status = Environment.getExternalStorageState();
long freeSpace = 0;
if (status.equals(Environment.MEDIA_MOUNTED)) {
try {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
freeSpace = availableBlocks * blockSize / 1024;
} catch (Exception e) {
e.printStackTrace();
}
} else {
return -1;
}
return (freeSpace);
}
示例5: getFile
import android.os.Environment; //导入方法依赖的package包/类
/**
* 根据文件名称和路径,获取sd卡中的文件,以File形式返回byte
*/
public static File getFile(String fileName, String folder)
throws IOException {
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
File pathFile = new File(Environment.getExternalStorageDirectory()
+ folder);
// && !pathFile .isDirectory()
if (!pathFile.exists()) {
pathFile.mkdirs();
}
File file = new File(pathFile, fileName);
return file;
}
return null;
}
示例6: isExternalStorageWritable
import android.os.Environment; //导入方法依赖的package包/类
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
示例7: getFreeExternalStorageSpace
import android.os.Environment; //导入方法依赖的package包/类
/**
* Get the free space in external storage
*
* @return Size in KB or -1 if not available
*/
public static long getFreeExternalStorageSpace() {
String status = Environment.getExternalStorageState();
long freeSpaceInBytes = 0;
// Check if external storage exists
if (status.equals(Environment.MEDIA_MOUNTED)) {
freeSpaceInBytes = getFreeSpaceInBytes(Environment.getExternalStorageDirectory().getPath());
} else {
// If no external storage then return -1
return -1;
}
return freeSpaceInBytes / 1024;
}
示例8: isExternalStorageReadable
import android.os.Environment; //导入方法依赖的package包/类
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
示例9: sdCardMounted
import android.os.Environment; //导入方法依赖的package包/类
public static boolean sdCardMounted() {
String state = Environment.getExternalStorageState();
if (!state.equals("mounted") || state.equals("mounted_ro")) {
return false;
}
return true;
}
示例10: getUsersDirectory
import android.os.Environment; //导入方法依赖的package包/类
public File getUsersDirectory() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return Environment.getExternalStorageDirectory();
} else {
return null;
}
}
示例11: isExternalStorageReadable
import android.os.Environment; //导入方法依赖的package包/类
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
示例12: sdcardMounted
import android.os.Environment; //导入方法依赖的package包/类
/**
* 检查是否安装了sd卡
*
* @return false 未安装
*/
public static boolean sdcardMounted()
{
final String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED) && !state.equals(Environment.MEDIA_MOUNTED_READ_ONLY))
{
return true;
}
return false;
}
示例13: hasSdcard
import android.os.Environment; //导入方法依赖的package包/类
public boolean hasSdcard() {
// TODO Auto-generated method stub
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
示例14: isExternalStorageWritable
import android.os.Environment; //导入方法依赖的package包/类
public static boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
示例15: createImagePathUri
import android.os.Environment; //导入方法依赖的package包/类
/**
* 创建一条图片地址uri,用于保存拍照后的照片
*
* @param context
* @return 图片的uri
*/
public static Uri createImagePathUri(final Context context) {
final Uri[] imageFilePath = {null};
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
imageFilePath[0] = Uri.parse("");
ToastUtil.error("请先获取写入SDCard权限");
} else {
String status = Environment.getExternalStorageState();
SimpleDateFormat timeFormatter = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA);
long time = System.currentTimeMillis();
String imageName = timeFormatter.format(new Date(time));
// ContentValues是我们希望这条记录被创建时包含的数据信息
ContentValues values = new ContentValues(3);
values.put(MediaStore.Images.Media.DISPLAY_NAME, imageName);
values.put(MediaStore.Images.Media.DATE_TAKEN, time);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
if (status.equals(Environment.MEDIA_MOUNTED)) {// 判断是否有SD卡,优先使用SD卡存储,当没有SD卡时使用手机存储
imageFilePath[0] = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} else {
imageFilePath[0] = context.getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
}
}
Log.i("", "生成的照片输出路径:" + imageFilePath[0].toString());
return imageFilePath[0];
}