Camera does not work

Asked

Viewed 79 times

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:

inserir a descrição da imagem aqui

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.

  • 1

    The phone was sitting on the table? :)

  • What information appears on Logcat when Activity turns black ?

  • 1

    @White does not kkkkkkkkkk

  • @Isac just solved, I restarted my phone and it worked '-' , more information: https://stackoverflow.com/questions/49869615/camera-does-not-work

1 answer

1


I made it work and you know how? I restarted the phone, and how did I find it? I tried to use Whastapp’s camera function and showed me the message that it was not possible to access the camera at that time, which was for me to restart, so after that, it magically worked. WWWTTFFFF -

More information about the question here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.