我遇到了从相机拍摄照片的问题。在我按下"取消"或"确认"按钮,它将返回主页而不是启动相机的活动。这是我的代码:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE_REQUEST);
我的代码可能有什么问题?感谢
修改1:
这是按钮点击监听器的代码:
DialogInterface.OnClickListener m_dialogOnclick = new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE_REQUEST);
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
}
};
许可:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
答案 0 :(得分:0)
您是否添加了onActivityResult
方法?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// Do something
} else if (resultCode == RESULT_CANCELED) {
// Do something else
}
}
}