Android App not asking for permissions when installing

家住魔仙堡 提交于 2019-11-30 07:52:48

问题


I work in the IT department of my university and we work on an app that installs the correct setup for the eduroam WiFi (maybe you have heard of it).

However I have a problem running it on my own LG G4 with Android 6.0. When installing the compiled *.apk it doesn't ask for any permissions although they are set in the AndroidManifest.xml. It was working on all previous Android versions.

Is it mandatory now to ask for permissions at run time?


回答1:


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.




回答2:


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);
        }
    }
}


来源:https://stackoverflow.com/questions/35701792/android-app-not-asking-for-permissions-when-installing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!