2014-07-17 5 views
1

이미지를 포함하는 폴더를 검색 한 다음 해당 폴더의 이미지를 표시하는 간단한 갤러리 앱을 개발 중입니다. 먼저 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" /> 

덕분에 여기 코드는 내가 사용 냈다입니다!

+0

참조이 : http://stackoverflow.com/questions/7616974/how-to-check-internal-and-external-storage-if-exist – Shadesblade

답변

0

MediaStore.Images 구성 요소에 시도해보십시오. 커서를 사용하여 이미지를로드하십시오. 문서 참조 : http://developer.android.com/reference/android/provider/MediaStore.html

+0

예, 미디어에 대한 나의 접근 방식을 변경했다 쿼리 및 잘 작동했습니다. 하지만 이제 나는 또 다른 문제에 직면 해있다. 응용 프로그램은 카메라를 사용하여 사진을 캡처의 기능이 있습니다. 나는 파일을 생성하고 카메라 정보에 파일 정보를 전달하려고합니다. 다른 기기에서 다시 작업하지만 Nexus 4에서 문제가 발생했습니다. 앱에서 파일을 만들 수 없습니다. 나는 환경을 시험했다. getexternalstoragedirextory 및 getCacheDir 모두 실패했습니다. Nexus 시리즈에서 카메라의 의도를 위해 파일을 만드는 방법 –

+0

매니페스트에서 올바른 권한을 요청하고 LogCat doodoo ...를 제공하는지 다시 확인하십시오. –

+0

내 질문을 업데이트했습니다. 그것 좀 봐주세요. 또한 Nexus 4 휴대 전화가 없습니다. 그래서 여기서 LogCat 출력을 제공 할 수는 없습니다. 감사합니다 –

관련 문제