3
I tried to access the camera phone, it worked 3 times, then the screen went black (Print below) in API 24, I tested it on a mobile phone with API 22 and it worked, with API 24 no, someone knows how to solve this?
public class fotos extends AppCompatActivity {
static final int REQUEST_IMAGE_CAPTURE = 1;
private ImageView ivPhoto;
private Button btTakeaaPhoto;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fotos);
ivPhoto = findViewById(R.id.ivPhoto);
btTakeaaPhoto = findViewById(R.id.btTakeaPhoto);;
btTakeaaPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//config.showProgress(true, progressBar, context);
dispatchTakePictureIntent();
}
});
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
ivPhoto.setImageBitmap(imageBitmap);
}
}
}
Print how the camera looks before closing and back to previous Activity:
The screen stays like this for a few seconds and then the camera closes and returns to activity.
The application does not stop working, it just opens the camera screen, gets black, and after a few seconds it closes, gives no execption, I’ve looked at the logcat.
Manifest :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"/>
What happened is not because of lack of permission, I have looked in the app settings, they have already been given.
The phone was sitting on the table? :)
– White
What information appears on Logcat when Activity turns black ?
– Isac
@White does not kkkkkkkkkk
– Woton Sampaio
@Isac just solved, I restarted my phone and it worked '-' , more information: https://stackoverflow.com/questions/49869615/camera-does-not-work
– Woton Sampaio