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



我有一个地图活动,我已经根据"危险权限"标准合并了我的代码以请求权限,但该代码无效,因为它没有在我的 android 手机上请求权限 (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()

在您的活动的onCreate()方法

相关内容

  • 没有找到相关文章

最新更新