运行"定位SDK 22" Android 6中的应用程序(SDK 23)

时间:2015-11-01 08:58:53

标签: android

我注意到当有人试图从Android 6(SDK 23)访问我的Android应用程序时出现以下问题:

java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.

由于修复此问题需要时间,因此我决定将应用程序目标SDK降级为 SDK 22

我的问题是:

  1. 是否可以运行"目标SDK 22" Android 6中的应用程序(SDK 23)?
  2. 上面的 SecurityException 有哪些解决方案? *我已经在我的Manifiest中授予了 ACCESS_FINE_LOCATION 权限

1 个答案:

答案 0 :(得分:0)

首先,设备应向后兼容(尽管这不是一揽子声明)Android 6.0 APIs以使用较低的SDK运行应用程序。您需要确保在ide中安装了SDK 22.

另一个是关于android 6的权限还有其他问题。

见这里:

Requesting Permissions at Run Time

从那里取得的示例检查权限

// Assume thisActivity is the current activity
int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
    Manifest.permission.WRITE_CALENDAR);

然后请求您需要的权限

// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
            Manifest.permission.READ_CONTACTS)
    != PackageManager.PERMISSION_GRANTED) {

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

    // Show an expanation to the user *asynchronously* -- don't block
    // this thread waiting for the user's response! After the user
    // sees the explanation, try again to request the permission.

    } else {

    // No explanation needed, we can request the permission.

    ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.READ_CONTACTS},
            MY_PERMISSIONS_REQUEST_READ_CONTACTS);

    // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
    // app-defined int constant. The callback method gets the
    // result of the request.
    }
}

这个答案包含更全面的解释。

https://stackoverflow.com/a/32084038/3956566