在我的应用程序中,我硬编码了捕获相机图像的路径。但是,这不适用于所有设备,因为不同设备的图像存储路径不同。有没有办法动态获取对所有设备都有效的路径?
这是我尝试过的:
if (externalStorageState.equals(Environment.MEDIA_MOUNTED)
|| externalStorageState.equals(Environment.MEDIA_UNMOUNTED)
|| externalStorageState
.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
File path = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM
+ "/Camera");//////////----path of captured images
Log.d("operator", " path: " + path);
if (path.exists()) {
if (path.isDirectory()) {
fo = new FileObserver(path.toString(),
FileObserver.CLOSE_WRITE) {
@Override
public void onEvent(int event, String path) {
SimpleDateFormat sdfDateT = new SimpleDateFormat(
"yy-MM-dd HH:mm:ss", Locale.US);
String st = sdfDateT.format(System
.currentTimeMillis());
Log.d("operator", "in event");
Log.d("operator", "lat: " + lat + " " + "lng: "
+ lng + " " + "location: " + addre + " " + "time: " + st);
ptd.insert(st, String.valueOf(lat), String.valueOf(lng), addre);
}
};