The code is as follows:
public class mainactivity extends Activity {
???? Private Button Btncamera ;
???? Private Button Btnlocalpic ;
???? Private ImageView ImageView ;
?
???? @Override
???? protected void onCreate (Bundle savedinstancestate) {
???????? // TODO auto-generated Method Stub
???????? Super . OnCreate (savedinstancestate);
???????? Setcontentview (r.layout. mainactivity );
???????? Btncamera = (Button) This . Findviewbyid (r.id. Btncamera );
???????? Btnlocalpic = (Button) This . Findviewbyid (r.id. Btnlocalpic );
???????? ImageView = (ImageView) This . Findviewbyid (r.id. ImageView1 );
?
???????? Btncamera . Setonclicklistener (new Onclicklistener () {
?
???????????? @Override
???????????? Public void OnClick (View arg0) {
???????????????? // TODO auto-generated Method Stub
???????????????? Intent Intent = new Intent (
???????????????????????? Android.provider.MediaStore. action_image_capture );
???????????????? Startactivityforresult (Intent, 1000);
????????????}
????????});
?
???????? Btnlocalpic . Setonclicklistener (new Onclicklistener () {
?
???????????? @Override
???????????? Public void OnClick (View arg0) {
???????????????? // TODO auto-generated Method Stub
???????????????? Intent Intent = new Intent (Intent. action_get_content );
???????????????? Intent.settype ("image/*");
???????????????? Intent.putextra ("crop", true);
???????????????? Intent.putextra ("Return-data", true);
???????????????? Startactivityforresult (Intent, 1001);
????????????}
????????});
????}
?
???? @Override
???? protected void onactivityresult (int requestcode, int ResultCode, Intent data) {
???????? // TODO auto-generated Method Stub
???????? Super . Onactivityresult (Requestcode, ResultCode, data);
???????? if (Requestcode = = && ResultCode = = result_ok) {
???????????? Bundle bundle = Data.getextras ();
???????????? Bitmap BM = (Bitmap) bundle.get ("data");
???????????? ImageView . Setimagebitmap (BM);
????????} Elseif (requestcode = = 1001 && ResultCode = = result_ok ) {
???????????? Uri uri = Data.getdata ();
???????????? Contentresolver contentresolver = Getcontentresolver ();
???????????? Try {
???????????????? Bitmap BM = bitmapfactory. Decodestream (Contentresolver
????????????????????????. Openinputstream (URI));
???????????????? ImageView . Setimagebitmap (BM);
????????????} catch (Exception e) {
???????????????? // TODO : Handle Exception
???????????????? E.printstacktrace ();
????????????}
????????}
????}
}
Android realizes photo and open local picture