1

I use geofences in my app. If user first switch location after first device run, he wes asked to agree Google location. But if user disagree, init of geofences return eror code 1000.

Is there any way to ask again to use Google location from my app?

I know about this questin, but this dialog launch only on first launch location setting. And if user disargee, there is IMHO no way to show dialog. Or is there any way?

Thank you for anwser

Community
  • 1
  • 1

1 Answers1

-1

As has been commented in your question, I'm not sure EXACTLY what you're asking, but you can test whether the user originally disagreed to location permissions using shouldShowRequestPermissionRationale.

Below is some expanded code based on the Requestion Permissions documentation that I use and that you may find helpful.

    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        Log.d(TAG, "checkMyPermissions ( " + permissionRequestCode + ") : Permissions FAILED");
        // Should we show an explanation?

        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            new AlertDialog.Builder(this)
                    .setMessage("In order to show data this app requires location permissions")
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(MainActivity.this,
                                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                    permissionRequestCode);
                        }
                    })
                    .setNegativeButton(android.R.string.cancel, null)
                    .show();

        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    permissionRequestCode);
        }
        return false;
    } else {
        Log.d(TAG, "checkMyPermissions ( " + permissionRequestCode + ") : Permissions Passed");
        return true;
    }
Simon Hutton
  • 1,677
  • 3
  • 22
  • 35
  • He is asking about Google's location service dialog (https://i.stack.imgur.com/ccg4k.png), not about custom permission request. – algarrobo Nov 20 '17 at 15:05