How get permission for camera in android.(Specifically Marshmallow)

前端 未结 6 1560
遇见更好的自我
遇见更好的自我 2020-11-30 01:53

Hey I am designing an app in android studio. In which i require permission of camera. I have included

6条回答
  •  有刺的猬
    2020-11-30 02:33

    This works for me, the source is here

    int MY_PERMISSIONS_REQUEST_CAMERA=0;
    // Here, this is the current activity
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
    {
         if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA))
         {
    
         }
         else
         {
              ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_CAMERA );
              // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
              // app-defined int constant. The callback method gets the
              // result of the request.
          }
    }
    

提交回复
热议问题