I'm building an application in Android Studio for my University class. It asks to upload pictures from my device, and I was thinking about trying taking also photos from the camera. I have to use only the Android Studio Emulator and not a real device, so, I'm not sure I can do it.
I solved as this:
Integer REQUEST_CAMERA = 1;
[...]
button_scatta.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK){
if (requestCode == REQUEST_CAMERA) {
Bundle bundle = data.getExtras();
final Bitmap bmp = (Bitmap) bundle.get("data");
ivImage.setImageBitmap(bmp);
}[...]
}
}
The Manifest has the following uses-permissions:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
I had this security error: java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.android.camera2/com.android.camera.CaptureActivity } from ProcessRecord{6d2a42a 7516:com.example.punta.geopost/u0a85} (pid=7516, uid=10085) with revoked permission android.permission.CAMERA