1

Mainifest 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>

my app need location permission I thought google play store would ask at the time of downloading but user have to set location manually.what is the way that google play store should ask what should I add in my code?

1 Answers1

1

If you're running in the android API version 23 or higher you'll need to require permissions at runtime. To ask for permissions you should do it right before using the feature that uses the permission:

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
}

Then override the onRequestPermissionsResult to see if the user has given the permission:

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

    }
}
Levi Moreira
  • 11,917
  • 4
  • 32
  • 46