简体   繁体   English

Android 应用程序在安装时不要求权限

[英]Android App not asking for permissions when installing

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).我在我大学的 IT 部门工作,我们开发了一个应用程序,可以为 eduroam WiFi 安装正确的设置(也许您听说过)。

However I have a problem running it on my own LG G4 with Android 6.0.但是,我在我自己的 LG G4 上使用 Android 6.0 运行它时遇到问题。 When installing the compiled *.apk it doesn't ask for any permissions although they are set in the AndroidManifest.xml.安装编译后的 *.apk 时,它不会要求任何权限,尽管它们是在 AndroidManifest.xml 中设置的。 It was working on all previous Android versions.它适用于所有以前的 Android 版本。

Is it mandatory now to ask for permissions at run time?现在是否必须在运行时请求权限?

If your target SDK version is 23 then you need to ask for "dangerous" permissions at run time.如果您的目标 SDK 版本是 23,那么您需要在运行时请求“危险”权限。

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 .如果是这种情况,那么如果您转到Settings > Apps > "Your app" > Permissions您应该能够看到未授予任何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.如果您还不想实施新系统,那么您可以将目标 sdk 版本降低到 22 以获得旧的权限系统。 You can still compile with sdk version 23 though.不过,您仍然可以使用 sdk 版本 23 进行编译。

See the documentation for more information.有关更多信息,请参阅文档

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

If the user is running Android 6.0 (API level 23) or later, the user has to grant your app its permissions while they are running the app.如果用户运行的是 Android 6.0(API 级别 23)或更高版本,则用户必须在运行应用程序时授予您的应用程序权限。 If you confront the user with a lot of requests for permissions at once, you may overwhelm the user and cause them to quit your app.如果您一次向用户提出大量权限请求,您可能会让用户不知所措并导致他们退出您的应用程序。 Instead, you should ask for permissions as you need them.相反,您应该在需要时请求权限。

In some cases, one or more permissions might be absolutely essential to your app.在某些情况下,一项或多项权限可能对您的应用程序绝对必要。 It might make sense to ask for all of those permissions as soon as the app launches.在应用程序启动后立即请求所有这些权限可能是有意义的。 For example, if you make a photography app, the app would need access to the device camera.例如,如果您制作了一个摄影应用程序,该应用程序将需要访问设备相机。 When the user launches the app for the first time, they won't be surprised to be asked for permission to use the camera.当用户第一次启动应用程序时,他们不会因为被要求获得使用相机的许可而感到惊讶。 But if the same app also had a feature to share photos with the user's contacts, you probably should not ask for the READ_CONTACTS permission at first launch.但是,如果同一个应用程序还具有与用户的联系人共享照片的功能,则您可能不应该在首次启动时请求 READ_CONTACTS 权限。 Instead, wait until the user tries to use the "sharing" feature and ask for the permission then.相反,等到用户尝试使用“共享”功能,然后请求许可。

If your app provides a tutorial, it may make sense to request the app's essential permissions at the end of the tutorial sequence.如果您的应用程序提供了教程,则在教程序列的末尾请求应用程序的基本权限可能是有意义的。

Source/ref https://developer.android.com/training/permissions/usage-notes来源/参考https://developer.android.com/training/permissions/usage-notes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM