你需要做兩件事。啓動相機應用程序,並告訴它在哪裏存儲,它需要的圖片:
File photo = new File(Environment.getExternalStorageDirectory(), "myFile.jpg");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
startActivityForResult(intent, myRequestCode);
當用戶關閉攝像頭應用程序,你的應用程序和活動將會恢復。所以,你必須覆蓋onActivityResult得到結果:
if (resultCode == myRequestCode){
File photo = new File(Environment.getExternalStorageDirectory(), "myFile.jpg");
// open it, show it, insert into MediaStore whatever
}
如果不提供保存的地方,則可以使用任何intent.getData或intent.getParcelableExtra使用Intent.EXTRA_STREAM或者檢索。
有你使用Camera類http://developer.android.com/reference/android/hardware/Camera.html –
您是否使用自定義的相機或攝像機開幕通過意圖? – Sujit
是我的相機正在使用意圖,我正在使用上述相機類。我用這些輸入更新了問題。 –