当前位置: 首页>>代码示例>>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;未经允许,请勿转载。