2017-03-08 2 views
0

je suivais le poste de
https://stackoverflow.com/a/10168114/5078763
et
http://www.theappguruz.com/blog/android-take-photo-camera-gallery-code-sample
modifié le code ci-dessousAndroid: Java image Picker de la galerie s'écraser question à GetBitmap

My App se bloque à

MediaStore.Images.Media.getBitmap 

Il exécute ci-dessous Bfr Log

Log.d("TAG", "onActivityResult: bfr"); 

Mais pas Afr Log

Log.d("TAG", "onActivityResult: Afr"); 

Mon Achevé code comme ci-dessous:

void calGlryImjPkrFnc() 
{ 
    Intent glrImjPkrVar = new Intent(Intent.ACTION_PICK, 
      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    glrImjPkrVar.setType("image/*"); 
    startActivityForResult(glrImjPkrVar , 1); 
} 

void calCamImjPkrFnc() 
{ 
    Intent camImjPkrVar = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    startActivityForResult(camImjPkrVar, 2); 
} 

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) 
{ 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    Bitmap pkdImjBitmapVar = null; 

    if(requestCode == 1 && resultCode == RESULT_OK) 
    { 
     Log.d("TAG",requestCode + ""); 
     if (imageReturnedIntent != null) 
     { 
      try 
      { 

       ContentResolver contntMgrVaj = getApplicationContext().getContentResolver(); 
       Uri uriVaj = imageReturnedIntent.getData(); 

       Log.d("TAG", "onActivityResult: bfr"); 

       pkdImjBitmapVar = MediaStore.Images.Media.getBitmap(contntMgrVaj, uriVaj); 

       Log.d("TAG", "onActivityResult: Afr"); 

      } 
      catch (IOException e) 
      { 
       e.printStackTrace(); 
      } 
     } 
    } 
    else if(requestCode == 2 && resultCode == RESULT_OK) 
    { 
     pkdImjBitmapVar = (Bitmap) imageReturnedIntent.getExtras().get("data"); 
    } 

    imjVyuVar.setImageBitmap(pkdImjBitmapVar); 
} 

Aidez-moi à réparer cet accident

+0

Veuillez fournir une erreur logcat ici. –

Répondre

0
void calCamImjPkrFnc() { 
    File image = new File("Your path you want to save file"); 
    Uri uriSavedImage = Uri.fromFile(image); 
    Intent camImjPkrVar = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); 
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uriSavedImage); 
    startActivityForResult(camImjPkrVar, 2); 
} 

Par add « android.provider .MediaStore.EXTRA_OUTPUT "travaille pour moi, j'espère que cela vous aidera.

+0

Cam fonctionne très bien pour moi
Prob est avec Gallery Picker –

1

Afficher le journal de plantage complet en premier. Cependant, vérifiez si uriVaj n'est pas null et votre permission d'application.

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