doesn't show picture in android 6 and above

后端 未结 2 1460
太阳男子
太阳男子 2020-12-07 06:38

I am trying to learn how to use the camera in an app and this is what I reached , the idea is having a button that opens the camera and that the picture will instantly show

2条回答
  •  日久生厌
    2020-12-07 07:09

    After android 6.0 permission structure has changed. You must check permission on run-time. For example you will select a picture from image gallery, User give permission for gallery access before entering gallery.

    You can look this document for this newness.

    https://developer.android.com/training/permissions/requesting.html

    Sample code for your issue

    if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Log.v(TAG,"Permission is granted");
            return true;
      }
    

    If not, you need to ask the user to grant your app a permission:

    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
    

    Good luck :)

提交回复
热议问题