Warnings Your Apk Is Using Permissions That Require A Privacy Policy: (android.permission.READ_PHONE_STATE)

前端 未结 20 1326
孤独总比滥情好
孤独总比滥情好 2020-12-01 00:53

In manifest not added android.permission.READ_PHONE_STATE. permission.

Why error comes when I upload a new apk version error comes below.

Your app has an apk w

20条回答
  •  春和景丽
    2020-12-01 01:50

    If you're testing your app on a device > android 6.0 you have also to explicitely ask the user to grant the permission.

    As you can see here READ_PHONE_STATE have a dangerous level.

    If a permission have a dangerous level then the user have to accept or not this permission manually. You don't have the choice, you MUST do this

    To do this from your activity execute the following code :

    if the user use Android M and didn't grant the permission yet it will ask for it.

    public static final int READ_PHONE_STATE_PERMISSION = 100;
    
      if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
                    != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, READ_PHONE_STATE_PERMISSION);
            }
    

    then override onRequestPermissionsResult in your activity

    @Override
        public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
            switch (requestCode){
                case READ_PHONE_STATE_PERMISSION: {
                    if (grantResults[0] == PackageManager.PERMISSION_GRANTED){
                        //Permission granted do what you want from this point
                    }else {
                        //Permission denied, manage this usecase
                    }
                }
            }
        }
    

    You should read this article to know more about it

提交回复
热议问题