camera code with interface to select from album or camera
Has开发者_Python百科 anyone implelemented a UI where you can choose from album or camera and then the camera opens and you can click and then click on a use button to use that. Please give any suggestions or reference project links
Thanks Max
use the below code to call UI to select camera or gallery,
private void openAddPhoto() {
String[] addPhoto=new String[]{ "Camera" , "Gallery" };
AlertDialog.Builder dialog=new AlertDialog.Builder(this);
dialog.setTitle(getResources().getString(R.string.method));
dialog.setItems(addPhoto,new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int id) {
if(id==0){
// Call camera Intent
}
if(id==1){
//call gallery
}
}
});
dialog.setNeutralButton("cancel",new android.content.DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}});
dialog.show();
}
Here is a former question & answer for the select-dialog: Allow user to select camera or gallery for image
just use this Camera Preview sample from google to get an image.
write that image to sd card then with the code from this sample: DataStorage
and then use an image-view layout to display the former written file: ImageView
精彩评论