Safcode Institute by Sir Safder





  • Image Capture and Display

    /* Just Image Capture */
    public class MainActivity extends AppCompatActivity {
        Button bt;
        static final int REQUEST_IMAGE_CAPTURE = 1;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    
            bt = (Button) findViewById(R.id.button);
    
            bt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(i, REQUEST_IMAGE_CAPTURE);
                }
            });
    
        }
    }
    
    
    /*Image Capture and Show in ImageView */
    public class MainActivity extends AppCompatActivity {
        Button b1;
        ImageView img;
        public static final int request = 1000;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            b1 = (Button) findViewById(R.id.button);
            img = (ImageView) findViewById(R.id.imageView);
            b1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
    
                    Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(i, request);
                }
            });
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == request) {
                Bitmap p = (Bitmap) data.getExtras().get("data");
                img.setImageBitmap(p);
            }
        }
    }



  • You Can Also Watch Our Tutorial