2016-07-26 77 views
-2

Intent.getData()返回在Android API 23上的null並且對於以前的版本正常工作?Intent.getData()在Android API上返回null 23

private void takePicture() { 
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 
    startActivityForResult(intent, 0); 
} 

...

private void choosePicture() 
{ 
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); 
    photoPickerIntent.setType("image/*"); 
    startActivityForResult(photoPickerIntent, 1); 
} 

...

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    ... 
    Uri selectedImage = data.getData(); 
    String imagePath = getPath(selectedImage); 
    dest = new File(imagePath); 
    decodeFile(imagePath); 
    ... 
} 
+0

它可以有什麼關係運行的權限6.0? – Vucko

+0

確實是授予的權限:'Manifest.permission.READ_EXTERNAL_STORAGE'' Manifest.permission.CAMERA' – Abdellah

+0

@Vucko正在寫外部存儲失蹤:/? – Abdellah

回答

0
public boolean ifPermissionReady(){ 
     if (ContextCompat.checkSelfPermission(getActivity(), 
       Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED){ 
      System.out.println("req camera permission*****"); 
      checkPermission(Manifest.permission.CAMERA, Constant.PERMISSION_CAMERA); 
      return false; 
     } 

     if (ContextCompat.checkSelfPermission(getActivity(), 
       Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){ 
      System.out.println("req write storage permission*****"); 
      checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, Constant.PERMISSION_WRITE_EXTERNAL_STORAGE); 
      return false; 
     } 
     return true; 
    } 

先嚐試調用這個函數。確保你獲得許可。 API23要求這樣做。點擊啓用相機拍照時運行它。您是否能夠在沒有此功能的情況下啓動相機?我的應用程序會崩潰,如果我不這樣做在API 23

0

如果data.getData()返回null,則嘗試:

 Bundle extras = data.getExtras(); 
     Bitmap bitmap = (Bitmap) extras.get("data"); 
相關問題