2011-10-15 2 views
2

사용자가 카메라의 새로운 이미지, 갤러리의 이미지 또는 일반 오래된 파일 중 하나를 선택할 수있는 응용 프로그램에서 작업하고 있습니다. 그런 다음 선택한 항목의 아이콘과 이름을 표시합니다. 나는이 예외를 가지고 일하고있다. 갤러리 응용 프로그램은 picasaweb 사진을 통합합니다. 사용자가 Picasa 앨범에서 사진을 선택하면 미리보기 이미지를 얻을 수 없습니다.갤러리에서 선택한 Picasa 이미지에 대한 미리보기 이미지는 어떻게 얻을 수 있습니까?

MediaStore.Images.Thumbnails.getThumbnail() 메서드를 사용하고 있는데 갤러리의 다른 이미지에도 잘 작동하지만 picasaweb 파일의 경우 축소판 그림의 "종류"에 관계없이 가져옵니다. (MICRO가 난 후 무엇을하더라도) 취득을 시도 :

ERROR/MiniThumbFile (2051) :있어 예외 전체 마법, ID = 5634890756050069570, 디스크를 읽거나 읽기 전용 마운트 할 때? 클래스 java.lang.IllegalArgumentException

선택한 파일의 URI가 다른 것으로 나타났습니다.

내용 : 지역 이미지 파일과 같이

내용 : // COM // 미디어/외부/이미지/미디어/6912

및 Picasa 웹 앨범 URL이 같이 .android.gallery3d.provider/Picasa를/아이템/5634890756050069570

내가 Thumbnails.queryMiniThumbnails를 사용하여 원시 THUMB_DATA에서 얻을 수있는 쿼리를 사용하려고() Thumbnails.THUMB_DATA가 프로젝션 배열에 있지만 "해당 열 없음"오류가 표시됩니다.

더 잘 작동하는 미리보기 이미지를 가져 오는 또 다른 방법이 있습니까? 전체 이미지 데이터에 액세스하려고하면 동일한 문제가 발생합니까?

+0

내가 쉽게 URI의 차이를 확인할 수 있습니다, 그리고 이미지가 Picasa에서 오는 경우 토스트를 표시 그러나 그것은 이상적이지 않습니다. 더 좋지만 완벽한 것은 아니지만 ACTION_PICK에서 picasa 이미지를 제외시키는 것이지만 그 방법을 알 수는 없습니다. – Mark

+0

Android 버그 추적기에이 문제가 발생했습니다. http://code.google.com/p/android/issues/detail?id=21234&q=picasa&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars – Mark

답변

2

내 Galaxy Nexus에서 Picassa의 이미지는 /sdcard/Android/data/com.google.android.apps.plus/cache 디렉토리 아래의 하위 디렉토리 중 하나에 저장되어 있습니다. 콘텐츠 제공 업체가 com.google.android.gallery3d.provider 인 경우 URL의 '항목'뒤에있는 숫자에는 이미지 이름 (위의 예에서 '5634890756050069570')이 포함됩니다. 이 데이터는 확장명이 ".screen"인 /sdcard/Android/data/com.google.android.apps.plus/cache 아래의 하위 디렉토리 중 하나에있는 파일에 해당합니다. DDMS를 사용하여 전화기 (이 경우 5634890756050069570.screen)에서이 이미지를 복사하고 확장명을 ".jpeg"로 바꾸면 이미지를 열고 컴퓨터에서 볼 수 있습니다.

다음 onActivityResult 메소드는 반환되는 콘텐츠 공급자를 확인한 다음 /sdcard/Android/data/com.google.android.apps.plus/cache 디렉토리에서 파일을 반복적으로 검색합니다. private 멤버 변수 인 fileSearchPathResults는 재귀 적 검색 메서드 인 walkDirectoryRecursivelySearchingForFile()에 의해 채워집니다.파일 경로와

private String fileSearchPathResult = null; 

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    Uri selectedImage = data.getData(); 
      String[] filePathColumn = { MediaStore.Images.Media.DATA }; 
      String filePath = null; 

      // This code is required to get the image path on content providers 
      // on API > 10 where the image is from a picassa web album, since Google changed 
      // the content provider in versions with API > 10 
      if (selectedImage.toString().contains("com.google.android.gallery3d.provider")) { 
       StringBuilder contentProviderPath = new StringBuilder(selectedImage.toString()); 
       int beginningIndex = contentProviderPath.lastIndexOf("/"); 
       String fileNameWithoutExt = contentProviderPath.subSequence(beginningIndex + 1, 
         contentProviderPath.length()).toString(); 
       Log.i(TAG, fileNameWithoutExt); 
       try { 
        File path = new File("/sdcard/Android/data/com.google.android.apps.plus/cache"); 
        if (path.exists() && path.isDirectory()) { 
         fileSearchPathResult = null; 
         walkDirectoryRecursivelySearchingForFile(fileNameWithoutExt, path); 
         if (fileSearchPathResult != null) { 
          filePath = fileSearchPathResult; 
         } 
        } 
       } catch (Exception e) { 
        Log.i(TAG, "Picassa gallery content provider directory not found."); 
       } 
      } 
    } 


    public void walkDirectoryRecursivelySearchingForFile(String fileName, File dir) { 
     String pattern = fileName; 

     File listFile[] = dir.listFiles(); 
     if (listFile != null) { 
      for (int i = 0; i < listFile.length; i++) { 
       if (listFile[i].isDirectory()) { 
        walkDirectoryRecursivelySearchingForFile(fileName, listFile[i]); 
       } else { 
        if (listFile[i].getName().contains(pattern)) { 
         fileSearchPathResult = listFile[i].getPath(); 
        } 
       } 
      } 
     } 
    } 

, 다음과 같은 코드를 사용하여 이미지의 비트 맵 만들 수 있습니다

 Bitmap sourceImageBitmap = BitmapFactory.decodeFile(filePath); 
+0

Galaxy Nexus에서 Picasa 파일을 찾는 데 문제가있어서이 솔루션이 저에게 효과적이었습니다. 고맙습니다. 그러나 구글 문자열에 대한 언급은 취성의 종류처럼 보인다. 다른 휴대 전화에서도 작동합니까? 그리고 이러한 특정 하드 코딩 된 문자열에 의존하지 않는보다 일반적인 솔루션이 있습니까 ?? – gcl1

+0

이 방법이 효과적이지만이 버퍼 영역은 다른 영역에있을 수 있습니다. AFAIK, Picasa 이미지에 더 많은 보안을 제공하기 위해이 새로운 콘텐츠 제공 업체가 Google에 추가되었습니다. 앱에서 URL을 읽을 때 일회용 사용 예외가 발생합니다. 그러면 다음 번에 URL을 다시 사용하면 앱이 터질 것입니다. 이미지를 더 많이 사용해야하는 경우 자신의 캐싱 영역에 복사본을 만들어야합니다 (단, 해당 영역이 공개 인 경우 더 많은 보안 허점이 생깁니다). – kenyee

0

ACTIVITYRESULT_CHOOSEPICTURE는 startActivity (intent, requestCode)를 호출 할 때 사용하는 int입니다.

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if(requestCode == ACTIVITYRESULT_CHOOSEPICTURE) { 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inSampleSize = 4; 
    final InputStream is = context.getContentResolver().openInputStream(intent.getData()); 
    final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); 
    is.close(); 
    } 
} 

코드가 전체 이미지를로드합니다. 엄지 손톱 크기의 이미지를 얻기 위해 샘플 크기를 적당한 값으로 조정할 수 있습니다.

+0

분명히 핵심 문제는 내가 com.android를 받고 있다는 것입니다. .gallery3d.provider이며 com.google.android.gallery3d.provider 여야합니다. 어떤 이유로이 모토로라 xoom에 깨진 것 같습니다. – Mark