이미지를 포함하는 폴더를 검색 한 다음 해당 폴더의 이미지를 표시하는 간단한 갤러리 앱을 개발 중입니다. 먼저 Environment.getExternalStorageDirectory()
을 사용한 다음 이미지가있는 폴더를 재귀 적으로 검색합니다. 그것은 좋은 시뮬레이터 및 장치를 작동합니다. 내 클라이언트가 Nexus 4에 앱을 설치하면 아무 것도로드되지 않습니다. Nexus 시리즈에 외장형 SD 슬롯이 없다고하는 게시물을 보았습니다. 디버깅에 Nexus 4가 없으며 클라이언트가 기술적이지 않습니다. 그는 문제의 원인을 찾기 위해 스스로 문제를 해결할 수 있습니다. 아무도이 점에서 도움을 줄 수 있습니까? 문제가 Nexus에는 적용되지 않는 Environment.getExternalStorageDirectory()
전화에 있다고 생각합니다. 어떻게이 문제를 해결할 수 있을지 생각해?Nexus 4의 모든 갤러리 이미지 가져 오기
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File cacheDir = null;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
cacheDir=new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath(), "MyImages");
}
else {
cacheDir = getCacheDir();
}
if(!cacheDir.exists()) {
cacheDir.mkdir();
}
// File storageDir = Environment.getExternalStoragePublicDirectory(
// Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
cacheDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "" + image.getAbsolutePath();
return image;
}
public void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
그리고 여기 매니페스트 추가 한 권한을 :
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
덕분에 여기 코드는 내가 사용 냈다입니다!
참조이 : http://stackoverflow.com/questions/7616974/how-to-check-internal-and-external-storage-if-exist – Shadesblade