1

My application asks for permission for ACCESS_FINE_LOCATION upon geolocation permission request fired from a webview, but it calls onRequestPermissionsResult without even showing dialog, with PERMISSION_DENIED for its response. I have read nearly all posts regarding this topic, but none of them seem to resolve my problem :(

in WebChromeClient:

@Override
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
    int permissionCheck = ContextCompat.checkSelfPermission(onActivity, android.Manifest.permission.ACCESS_FINE_LOCATION);
    if (permissionCheck == -1){
        ActivityCompat.requestPermissions(onActivity, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, MainActivity.REQUEST_GEOLOCATION);
    }else if (permissionCheck == 0){
        callback.invoke(origin, true, false);
    }
}

following are requested permissions from my manifest

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="28"
    tools:ignore="ScopedStorage"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.Manifest.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.Manifest.permission.ACCESS_FINE_LOCATION" />

For sdk version, I have minSdkVersion 23, targetSdkVersion 29.

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
IChung
  • 347
  • 1
  • 3
  • 8

1 Answers1

2

Replace:

<uses-permission android:name="android.Manifest.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.Manifest.permission.ACCESS_FINE_LOCATION" />

with:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • i'm surprised this would even compile for OP, does that mean there's no actual generated code or check produced based on permissions ? – a_local_nobody Sep 01 '21 at 10:59
  • @a_local_nobody: "i'm surprised this would even compile for OP" -- since permission names are arbitrary strings, there is no way to know that those are invalid. I could see them adding a Lint warning saying "um, you sure about that?", but probably not an error. – CommonsWare Sep 01 '21 at 11:00
  • perhaps out of the scope of this question, but while i have your time i might as well ask - is there any actual scenario where a custom permission would be useful or needed ? considering that they then aren't validated, is there a usecase for writing "my.foo.permission" ? – a_local_nobody Sep 01 '21 at 11:04
  • WOW thanks, never thought mindless copy and paste have caused the problem – IChung Sep 01 '21 at 11:06
  • apparently, [there's a reason](https://developer.android.com/guide/topics/permissions/defining) – a_local_nobody Sep 01 '21 at 11:07
  • 1
    @a_local_nobody: Custom permissions were designed around pre-installed app suites, such as for device manufacturers. It is possible to use them for app suites installed by users, or even possibly for other multi-app scenarios (e.g., main app and third-party plugins). Custom permissions behave a bit weird, and so I am grateful that most developers do not need them. – CommonsWare Sep 01 '21 at 11:11