mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Add onRequestPermissionsResult()
This commit is contained in:
parent
3bd1baaf8d
commit
361196bedd
1 changed files with 15 additions and 1 deletions
|
|
@ -99,13 +99,27 @@ public class NearbyActivity extends NavigationBaseActivity {
|
||||||
private void checkLocationPermission() {
|
private void checkLocationPermission() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
//Request permission and display notification that Nearby places cannot be shown without permission
|
|
||||||
ActivityCompat.requestPermissions(this,
|
ActivityCompat.requestPermissions(this,
|
||||||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST);
|
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
|
switch (requestCode) {
|
||||||
|
case LOCATION_REQUEST: {
|
||||||
|
if (grantResults.length > 0 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
//If permission not granted, display notification that Nearby Places cannot be displayed
|
||||||
|
int duration = Toast.LENGTH_LONG;
|
||||||
|
Toast toast = Toast.makeText(this, "Nearby places cannot be found without location permissions", duration);
|
||||||
|
toast.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void checkGps() {
|
protected void checkGps() {
|
||||||
LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||||
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue