本文整理匯總了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];
}