2015-01-12 3 views
0

이상한 행동이 발생합니다. 나는 의도를 사용하여 갤러리를 기르고 자 노력하고있다. 그런 다음 onActivityResult()를 사용하여 Uri를 가져 와서 Bitmap으로 변환하려고합니다. 내가 직면 한 문제는 이미지를 먼저 선택하면 휴대 전화가 몇 초 동결됩니다. 그런 다음 onActivityResult()로 반환 할 때까지 이미지를 선택 했는데도 resultCode 값은 -1입니다. 내 걸음에서 뭔가를 놓치고 있니?갤러리 의도가 작동하지 않습니다.

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // TODO Auto-generated method stub 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == GALLERY_REQUEST_CODE) { 
     Uri selectedImageUri = data.getData(); 
     if (selectedImageUri != null) { 
      try { 
       String[] filePathColumn = { MediaStore.Images.Media.DATA }; 
       Cursor cursor = getContentResolver().query(
         selectedImageUri, filePathColumn, null, null, null); 
       cursor.moveToFirst(); 
       int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
       String filePath = cursor.getString(columnIndex); 
       cursor.close(); 

       Bitmap mBitmap = BitmapFactory.decodeFile(filePath); 
       LogUtil.e(TAG, "mBitmap: " + mBitmap); 
       ByteArrayOutputStream bs = new ByteArrayOutputStream(); 
       mBitmap.compress(Bitmap.CompressFormat.PNG, 50, bs); 

       Intent intent = new Intent(CameraActivity.this, 
         SecondActivity.class); 
       intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP 
         | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       intent.putExtra("image", bs.toByteArray()); 
       startActivity(intent); 
      } catch (FileNotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    } else { 
     return; 
    } 
} 

업데이트

시작 갤러리 의도

Intent intent = new Intent(Intent.ACTION_PICK, 
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
startActivityForResult(intent, GALLERY_REQUEST_CODE); 

내 onActivityResult를 : 나는 매니페스트에 권한이 있습니다. 나는 올바른 우 리도 받고있다. 그러나 이미지를 선택한 후에는 항상 resultCode = -1을받습니다. 바인더 트랜잭션에 실패했습니다.

권한이 누락 되었나요? 미리 감사드립니다.

+0

http://stackoverflow.com/questions/2507898/how-to-pick-an-image-from-gallery-sd-card-for-my-app – Praveen

+0

@Praveen, 즉 코드의 I는 이것을 프로그래밍 할 때 참조됩니다. 그것은 내 resultCode가 이미지를 선택한 후 -1이기 때문에 중요하지 않습니다. OK 상태 값을 얻을 수 없습니다 – portfoliobuilder

답변

1

이 코드를 작성하려면 매니페스트에이 권한이 있는지 확인하십시오.

<manifest ...> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    ... 
</manifest> 
+0

이것은 충돌을 수정하지 않습니다. 갤러리에서 이미지를 선택한 후에도 앱으로 돌아가려면 몇 초가 걸립니다. resultCode = -1, 아직 이미지에서 올바른 Uri를 검색하고있는 것을 볼 수 있습니다. 또한 새 활동을 시작하려는 의도도 작동하지 않습니다. – portfoliobuilder

+1

resultCode -1은 요청 처리, logcat 세부 사항 확인 및 게시에 오류가 있음을 의미합니다. – Techfist

+0

나는 일반적인 오류를 보지 못했고 그 점을별로 생각하지 않았습니다. 그러나 나는 지금 뭔가를 본다. 그것은 "실패한 바인더 트랜잭션"입니다. – portfoliobuilder