내 갤러리에서 이미지를 선택하고이를 내 애플리케이션에서 사용하는 데 문제가 있습니다. 나는이 의도 사용ACTION_PICK이 끝나기 전에 onActivityResult가 호출됩니다.
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, ACTIVITY_SELECT_PHOTO);
을하고 내가 이미지를 선택할 수있는 갤러리에 저를 제공합니다. 하지만 하나를 선택하는 순간 ACTION_PICK이 모든 것을 끝내지 않은 반면 onActivityResult는 immediatly, 이라고합니다. 글쎄, 그게 문제 야. 매니페스트의 활동에서 launchMode를 "singleTop"으로 변경해야한다고 읽었지만 작동하지 않았습니다. 또는 "ACTION_PICK"- launchivity의 launchMode를 변경해야합니까? 그리고 이것도 가능합니까?
final static int ACTIVITY_SELECT_PHOTO = 0;
final static int ACTIVITY_CAMERA_PHOTO = 1;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
Log.d("onActivityresult", "req = " + requestCode + ", result = " + resultCode);
switch(requestCode) {
case ACTIVITY_SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImageUri=imageReturnedIntent.getData();
String actualPath=getRealPathFromURI(selectedImageUri);
File file=new File(actualPath);
Bitmap b=decodeFile(file); //this is new bitmap which you can use for your purpose
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.PNG, 55, os);
compressedByteArray = os.toByteArray();
iv.setImageBitmap(b);
currentUser.put("picture", compressedByteArray);
Toast t = Toast.makeText(this, "Uploading picture...", Toast.LENGTH_LONG);
t.show();
currentUser.save();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
case ACTIVITY_CAMERA_PHOTO:
if(resultCode == RESULT_OK){
Bundle extras = imageReturnedIntent.getExtras();
//THE LINE BELOW THIS ONE GIVES NULLPOINTEREX WHICH IS OBVIOUS BECAUSE IT's ANOTHER //CASE
Bitmap bmp = (Bitmap)extras.get("data");
ByteArrayOutputStream os = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 55, os);
compressedByteArray = os.toByteArray();
bmp = BitmapFactory.decodeByteArray(compressedByteArray, 0, compressedByteArray.length);
iv.setImageBitmap(bmp);
currentUser.put("picture", compressedByteArray);
}
try {
Toast t = Toast.makeText(this, "Uploading picture...", Toast.LENGTH_LONG);
t.show();
currentUser.save();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
같은 ResultCode = -1 (그래서 RESULT_OK) 하지만 나에게 오류를 제공합니다
java.lang.RuntimeException가이: 실패 제공하는 결과가 null = ResultInfo가 {= 0, 결과를 요청 = -1 , data = Intent {dat = content : // media/external/images/media/173}} to {com.tapazz/com.tapazz.ShowProfileActivity} : null 예외는 null입니다. 다른 RequestCode (위의 "이 행"참조)
앱이 멈추지 만 다시 시작하면해야 할 것처럼 사진을 골랐다는 것을 알 수 있습니다.
괜찮아, 그건 내 바보 같았다 ... 그게 문제를 해결했다. 고마워. 남자 – dumazy