地图 apk 不要求位置访问权限

Map apk not asking for location access permission

我有一张地图 activity 并且我已经根据 'dangerous permissions' 标准合并了我的代码以请求许可,但是该代码无效,因为它没有在我的 [=] 上请求许可23=] phone (API 25).

我在AndroidManifest.xml中使用了这两个权限来启用访问权限。

var ACCESSLOCATION=143

fun checkPermission()
{
    if(Build.VERSION.SDK_INT>=23) //dangerous permission condition used
    {
        if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!=PackageManager.PERMISSION_GRANTED)
            requestPermissions(arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION), ACCESSLOCATION) 
    }
    getLocation()      
}

fun getLocation()
{
    Toast.makeText(this,"User Location access is on",Toast.LENGTH_LONG).show()
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>?, grantResults: IntArray?) {
    when(requestCode)
    {
        ACCESSLOCATION->
        {
            if(grantResults!![0]==PackageManager.PERMISSION_GRANTED)
                getLocation()
            else
            {
                Toast.makeText(this,"Access not granted to your location",Toast.LENGTH_LONG).show()
            }
        }
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}

AndroidManifest.xml 包含权限:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ritika.pokemonand">
    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or 
    fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
    <meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key" />

    <activity
    android:name=".MapsActivity"
    android:label="Pokemon">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    </application>

    </manifest>

我希望它显示一条弹出消息,请求访问权限。

您需要致电checkPermission()

在您的 activity

onCreate() 方法中