我的应用程序在从 google 下载时不请求权限播放 store.I 在我的清单文件中指定了位置权限

my app doesn't asks permission at the time of downloading from google play store.I have specified location permission in my manifest file

主要文件

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true" />

<application
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/hero3"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name="info.food360.nikhil.splash"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="info.food360.nikhil.MainActivity"
        android:windowSoftInputMode="adjustPan|adjustResize"
        android:theme="@style/AppTheme.NoActionBar"/>
    <activity
        android:name="info.food360.nikhil.DesActivity"
        android:configChanges="orientation|screenSize"
        android:label="DestinationActivity" />
    <activity android:name="info.food360.nikhil.Suggestion" />
    <activity android:name="info.food360.nikhil.LocationWork" />
    <activity android:name="info.food360.nikhil.logicBehind"></activity>
</application>

我的应用程序需要位置权限 我以为 google Play 商店会在下载时询问,但用户必须设置位置 manually.what 是 google Play 商店应该询问的方式我应该在我的代码中添加什么?

如果您 运行 在 android API 版本 23 或更高版本中,则需要在 runtime 中请求权限。要请求权限,您应该在使用使用该权限的功能之前这样做:

int MY_PERMISSIONS_REQUEST_LOCATION = 123;
if (ContextCompat.checkSelfPermission(thisActivity,
        Manifest.permission.ACCESS_FINE_LOCATION)
        != PackageManager.PERMISSION_GRANTED) {
    //app doesn't have permission yet

     ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                MY_PERMISSIONS_REQUEST_LOCATION);
} else {
    // Permission has already been granted
}

然后重写onRequestPermissionsResult,看看用户是否给了权限:

public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_LOCATION: {

            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // permission was granted
            } else {
                // permission denied
            }
            return;
        }

    }
}