android 手機拍照返回 Intent==null 以及intent.getData==null


 

手機拍照第一種情況;
private void takePicture(){

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
String filename = timeStampFormat.format(new Date());
ContentValues values = new ContentValues();
values.put(Media.TITLE, filename);
 photoUri =getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(intent, TAKE_PHOTO);

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {

data 未空,注意data 是指Intent    

原因:即指定了目標uri   如果指定了目標uri,data就沒有數據,如果沒有指定uri,則data就返回有數據!

可根據 photoUri全局變量獲取URI;

}

 

 

手機拍照第二種情況;
private void takePicture(){

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PHOTO);

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {

data 非空,注意data 是指Intent   

 

Uri uri=Intent.getData();

發現依舊返回null;由於測試機無SD卡 ,原因不詳,請知道的指教

解決方法:if(data.hasExtra("data")){

Bitmap bitMap = data.getParcelableExtra("data");得到圖片

}

 

 

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM