2016-06-30 59 views
-2

我目前正在爲我的應用程序的用戶配置文件。直到最近,我一直在測試三星Galaxy Note 4,它沒有給我任何問題,下面的代碼。然而,在後來的測試中,我將手放在Nexus 5x上,當我使用下面的代碼嘗試選擇用戶配置文件圖像時,出現錯誤「不幸的照片已停止」。我沒有任何錯誤日誌,因爲我無法調試照片。「不幸的照片已停止」當試圖拍照並使用裁剪功能

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch(requestCode) { 
     case 0: 
      if(resultCode == RESULT_OK){ 
       Uri selectedImage = data.getData(); 
       cropImage(selectedImage); 
      } 

      break; 
     case 1: 
      if(resultCode == RESULT_OK){ 
       Uri selectedImage = data.getData(); 
       cropImage(selectedImage); 
      } 
      break; 
     case 2: 
      if(resultCode == RESULT_OK){ 
       Uri selectedImage = data.getData(); 
       profileImage.setImageURI(selectedImage); 
       try { 
        userProfileImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage); 
        AlmightyFunctions.ImageService.saveProfileImage(user,userProfileImage); 
       } 
       catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 
      break; 
    } 
} 

public void showImageSelectDialog() { 
    CharSequence options[] = new CharSequence[] { 
      getString(R.string.select_camera), 
      getString(R.string.select_gallery) 
    }; 

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle(getString(R.string.select_image_dialog)); 
    builder.setItems(options, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      MarshMallowPermission mmp = new MarshMallowPermission(UserProfileActivity.this); 
      switch(which) { 
       case 0: 
        if (!mmp.checkPermissionForCamera()) { 
         mmp.requestPermissionForCamera(); 
        } 
        Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        startActivityForResult(takePicture, 0); 
        break; 
       case 1: 
        if (!mmp.checkPermissionForExternalStorage()) { 
         mmp.requestPermissionForExternalStorage(); 
        } 
        Intent pickPhoto = new Intent(Intent.ACTION_PICK, 
          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
        startActivityForResult(pickPhoto, 1); 
        break; 
      } 
     } 
    }); 
    builder.show(); 
} 

public void cropImage(Uri photoUri) { 
    Intent intent = new Intent("com.android.camera.action.CROP"); 
    intent.setDataAndType(photoUri, "image/*"); // this will open all images in the Gallery 
    intent.putExtra("crop", "true"); 
    intent.putExtra("aspectX", 1); // this defines the aspect ration 
    intent.putExtra("aspectY", 1); 
    intent.putExtra("return-data", true); // true to return a Bitmap, false to directly save the cropped iamge 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); //save output image in uri 
    startActivityForResult(intent,2); 
} 

任何幫助將不勝感激。

回答