Created
February 6, 2022 12:24
-
-
Save nisaefendioglu/e659f9692d5dcf41ba8cf8ff1f9aed05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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