-5

I am designing an app in android studio.i have included the all permission like CAMERA and READCONTECTS etc... in the AndroidManifest.xml file. It is working properly in all versions of android except Marshmallow. How do I set all permission by default?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ramesh Yogu
  • 135
  • 7

1 Answers1

0

You need to set permission on the java code also before it works

Example:

//declaration
private static final Integer CAMERA = 0x1;

//call this 
askForPermission(Manifest.permission.CAMERA, CAMERA);

    /**
     *
     * @param permission
     * @param requestCode
     */
    private void askForPermission(String permission, Integer requestCode) {
        if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {

                //This is called if user has denied the permission before
                //In this case I am just asking the permission again
                ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);

            } else {

                ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
            }
        } else {
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                           int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if(ActivityCompat.checkSelfPermission(this, permissions[0]) ==
                PackageManager.PERMISSION_GRANTED){
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {
            }
        }else{
            Toast.makeText(this, "Permission not granted", Toast.LENGTH_SHORT).show();
        }
    }