當前位置: 首頁>>代碼示例>>Java>>正文


Java Environment.getExternalStorageState方法代碼示例

本文整理匯總了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/";
}
 
開發者ID:Sherchen,項目名稱:AnimationsDemo,代碼行數:13,代碼來源:FileUtils.java

示例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);
  }
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:25,代碼來源:Camcorder.java

示例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);

}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:24,代碼來源:MainSettingsActivity.java

示例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);
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:23,代碼來源:FileUtils.java

示例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;
}
 
開發者ID:Horrarndoo,項目名稱:YiZhi,代碼行數:19,代碼來源:FileUtils.java

示例6: isExternalStorageWritable

import android.os.Environment; //導入方法依賴的package包/類
public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:8,代碼來源:SysUtils.java

示例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;
}
 
開發者ID:alex-shpak,項目名稱:keemob,代碼行數:20,代碼來源:DirectoryManager.java

示例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;
}
 
開發者ID:HTBridge,項目名稱:pivaa,代碼行數:8,代碼來源:Authentication.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:8,代碼來源:LetvCacheTools.java

示例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;
    }
}
 
開發者ID:OlegKlimenko,項目名稱:Plamber-Android,代碼行數:9,代碼來源:Utils.java

示例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;
}
 
開發者ID:kashifo,項目名稱:android-folder-picker-library,代碼行數:9,代碼來源:FolderPicker.java

示例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;
}
 
開發者ID:BaoBaoJianqiang,項目名稱:AndroidNetwork,代碼行數:15,代碼來源:BaseUtils.java

示例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;
	}
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:10,代碼來源:RegisterIdActivity.java

示例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;
}
 
開發者ID:ShaunSheep,項目名稱:ScaleSketchPadDemo,代碼行數:8,代碼來源:BitmapUtils.java

示例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];
}
 
開發者ID:ChunweiDu,項目名稱:Utils,代碼行數:35,代碼來源:PhotoUtil.java


注:本文中的android.os.Environment.getExternalStorageState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。