Java Code Examples for android.os.Environment.getExternalStorageState()

The following are Jave code examples for showing how to use getExternalStorageState() of the android.os.Environment class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: appinventor-extensions   File: Camcorder.java   View Source Code Vote up 7 votes
/**
 * 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);
  }
}
 
Example 2
Project: AnimationsDemo   File: FileUtils.java   View Source Code Vote up 6 votes
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/";
}
 
Example 3
Project: buildAPKsApps   File: MainSettingsActivity.java   View Source Code Vote up 6 votes
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);

}
 
Example 4
Project: Pluto-Android   File: FileUtils.java   View Source Code Vote up 6 votes
/**
 * 计算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);
}
 
Example 5
Project: YiZhi   File: FileUtils.java   View Source Code Vote up 6 votes
/**
 * 根据文件名称和路径,获取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;
}
 
Example 6
Project: javaide   File: SysUtils.java   View Source Code Vote up 5 votes
public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}
 
Example 7
Project: keemob   File: DirectoryManager.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 8
Project: pivaa   File: Authentication.java   View Source Code Vote up 5 votes
public boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}
 
Example 9
Project: letv   File: LetvCacheTools.java   View Source Code Vote up 5 votes
public static boolean sdCardMounted() {
    String state = Environment.getExternalStorageState();
    if (!state.equals("mounted") || state.equals("mounted_ro")) {
        return false;
    }
    return true;
}
 
Example 10
Project: Plamber-Android   File: Utils.java   View Source Code Vote up 5 votes
public File getUsersDirectory() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return Environment.getExternalStorageDirectory();
    } else {
        return null;
    }
}
 
Example 11
Project: android-folder-picker-library   File: FolderPicker.java   View Source Code Vote up 5 votes
public boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) ||
            Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}
 
Example 12
Project: localcloud_fe   File: DirectoryManager.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 13
Project: AndroidNetwork   File: BaseUtils.java   View Source Code Vote up 5 votes
/**
 * 检查是否安装了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;
}
 
Example 14
Project: HiBangClient   File: RegisterIdActivity.java   View Source Code Vote up 5 votes
public boolean hasSdcard() {
	// TODO Auto-generated method stub
	String state = Environment.getExternalStorageState();
	if (state.equals(Environment.MEDIA_MOUNTED)) {
		return true;
	} else {
		return false;
	}
}
 
Example 15
Project: ScaleSketchPadDemo   File: BitmapUtils.java   View Source Code Vote up 5 votes
public static boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}
 
Example 16
Project: Utils   File: PhotoUtil.java   View Source Code Vote up 5 votes
/**
 * 创建一条图片地址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];
}
 
Example 17
Project: localcloud_fe   File: DirectoryManager.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 18
Project: LQRWeChat-master   File: RongGenerate.java   View Source Code Vote up 5 votes
private static void createDir(String saveaddress) {
    boolean b;
    String status = Environment.getExternalStorageState();
    b = status.equals(Environment.MEDIA_MOUNTED);
    if (b) {
        File destDir = new File(saveaddress);
        if (!destDir.exists()) {
            destDir.mkdirs();
        }
    }
}
 
Example 19
Project: LQRWeChat   File: RongGenerate.java   View Source Code Vote up 5 votes
private static void createDir(String saveaddress) {
    boolean b;
    String status = Environment.getExternalStorageState();
    b = status.equals(Environment.MEDIA_MOUNTED);
    if (b) {
        File destDir = new File(saveaddress);
        if (!destDir.exists()) {
            destDir.mkdirs();
        }
    }
}
 
Example 20
Project: PhotoFactory   File: SystemUtils.java   View Source Code Vote up 5 votes
/**
 * 检查设备是否存在SDCard的工具方法
 */
public static boolean HasSdcard() {
    String state = Environment.getExternalStorageState();
    if (state.equals(Environment.MEDIA_MOUNTED)) {
        // 有存储的SDCard
        return true;
    } else {
        return false;
    }
}