Android App not asking for permissions when installing

北战南征 提交于 2019-11-29 05:33:18

If your target SDK version is 23 then you need to ask for "dangerous" permissions at run time.

If this is the case then you should be able to see that no permissions have been granted if you go to Settings > Apps > "Your app" > Permissions.

If you don't want to do implement the new system yet then you can reduce your target sdk version to 22 to get the old permission system. You can still compile with sdk version 23 though.

See the documentation for more information.

Vanya Sakharovskiy

if you want to request permissions at runtime you should write a special request in your app. Something like this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        createPermissions();
}
public void createPermissions(){
    String permission = Manifest.permission.READ_SMS;
    if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED){    
        if(!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)){
              requestPermissions(new String[]{permission}),
                        SMS_PERMISSION);
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!