Skip to content

Instantly share code, notes, and snippets.

@illuzor
Created May 1, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/63b4c667247fb563f60b383aa24cd458 to your computer and use it in GitHub Desktop.
Save illuzor/63b4c667247fb563f60b383aa24cd458 to your computer and use it in GitHub Desktop.
package com.example.cameraintenttest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
findViewById(R.id.button).setOnClickListener(v ->
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), 0)
);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == 0 && resultCode == RESULT_OK) {
Bitmap image = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
super.onActivityResult(requestCode, resultCode, data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment