如何判断是否该SD卡安装在机器人? [英] How to tell if the sdcard is mounted in Android?
问题描述
我的工作,需要看什么图片用户存储一个Android应用程序。的问题是,如果用户具有安装经由USB线缆的SD卡,我无法读取图像列表在磁盘上。
I'm working on an Android application that needs to look at what images a user has stored. The problem is that if the user has the sdcard mounted via the USB cable, I can't read the list of images on the disk.
有谁知道的方式告诉如果USB安装,这样我可以弹出一个消息,通知其将无法正常工作的用户?
Does anyone know of a way to tell if the usb is mounted so that I could just pop up a message informing the user that it won't work?
推荐答案
如果您尝试访问该设备上的图像,最好的方法是使用<一个href="http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html">MediaStore内容提供商。访问其作为内容提供商将允许您查询的是$ P $图像psent和地图内容://
网址到设备上的文件路径酌情
If you're trying to access images on the device, the best method is to use the MediaStore content provider. Accessing it as a content provider will allow you to query the images that are present, and map content://
URLs to filepaths on the device where appropriate.
如果您仍然需要访问的SD卡,相机应用程序包括<一href="http://android.git.kernel.org/?p=platform/packages/apps/Camera.git;a=blob;f=src/com/android/camera/ImageManager.java;h=073b8db811d1a010079c7a258a418aa90fae2326;hb=dafe31ead98304414f84f021bd0c155e62d833c2">ImageUtils类如下检查,如果安装在SD卡:
If you still need to access the SD card, the Camera application includes an ImageUtils class that checks if the SD card is mounted as follows:
static public boolean hasStorage(boolean requireWriteAccess) {
//TODO: After fix the bug, add "if (VERBOSE)" before logging errors.
String state = Environment.getExternalStorageState();
Log.v(TAG, "storage state is " + state);
if (Environment.MEDIA_MOUNTED.equals(state)) {
if (requireWriteAccess) {
boolean writable = checkFsWritable();
Log.v(TAG, "storage writable is " + writable);
return writable;
} else {
return true;
}
} else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
这篇关于如何判断是否该SD卡安装在机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!