Skip to content

Instantly share code, notes, and snippets.

@nisaefendioglu
Created February 6, 2022 12:24
Show Gist options
  • Save nisaefendioglu/e659f9692d5dcf41ba8cf8ff1f9aed05 to your computer and use it in GitHub Desktop.
Save nisaefendioglu/e659f9692d5dcf41ba8cf8ff1f9aed05 to your computer and use it in GitHub Desktop.
package com.example.cameraapp;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private Button btn_cek;
private ImageView imageView;
private static final int CAMERA_REQUEST=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_cek = (Button) findViewById(R.id.btn_cek);
imageView = (ImageView) findViewById(R.id.imageView);
btn_cek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,CAMERA_REQUEST);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)
{
Bitmap image = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment