Camera does not work

3

I tried to access the camera from the phone, it worked 3 times, then the screen went black (Print below) in API 24, I tested it on a cell phone with API 22 and it worked, with API 24, 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 is before closing and back to previous activity:

Thescreenstayslikethisforafewsecondsandthenthecameraclosesandreturnstotheativity.

Theapplicationdoesnotstopworking,itjustopensthecamerascreen,itturnsblack,andafterafewsecondsitcloses,doesnotgiveanyexecption,Ialreadylookedatlogcat.

Manifest:

<uses-permissionandroid: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"/>

This is not because of lack of permission, I already looked at the app settings, they have already been given.

    
asked by anonymous 17.04.2018 / 06:14

1 answer

1

I made it work and you know how? I restarted my cell phone, and how did I figure it out? I tried using the WhastApp camera function and it showed me the message that it was not possible to access the camera at that time, which was for me to reboot, so after that it magically worked. WWWTTFFFF -

More information on the question here

    
17.04.2018 / 13:24