There are 3 ways of get the image.
First, take a picture!
Second, get the picture in gallery!
Last is loading drawable image.
Run my example app.
Click to finger image!!
You can see alertDialog.
You can choose how to get image.
This is Dialog code.
- AlertDialog.Builder ad=new AlertDialog.Builder(this);
- ad.setTitle("How to get picture?")
- .setMessage("Click to button!!")
- .setPositiveButton("Take a picture!",new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- startActivityForResult(intent, intent_camera);
- }
- })
- .setNegativeButton("Getting the Gallery!",new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent=new Intent();
- intent.setAction(Intent.ACTION_GET_CONTENT);
- intent.setType("image/-");
- startActivityForResult(intent, intent_gallery);
- }
- })
- .setNeutralButton("Getting the basic image",new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- showPicture.setImageResource(R.drawable.click);
- }
- })
- .show();
Line 8~9 : run Camera!!
Line 16~19 : run Gallery.
Line 25 : get the drawable image!!
In case of camera & gallery,
You must use 'startActivityForResult' and 'onActivityResult'
Picture uri is use data.getData();
- Uri uri= data.getData();
- showPicture.setImageURI(uri);
No comments:
Post a Comment