Android Ask for permission to use location within webview

后端 未结 1 1391
天命终不由人
天命终不由人 2021-01-23 11:24

I have an application that uses a webview and inside the webview is a map, I have got it working to the user automatically find the users location with the following code:

1条回答
  •  一整个雨季
    2021-01-23 11:54

    That's because you need to create the prompt. The onGeolocationPermissionsShowPrompt function is simply called to let you know the webpage wants the location.

    callback.invoke(origin, true, false); is the response telling the WebView it's OK to use the location.

    The last argument is whether or not to remember this setting. See: http://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback.html

    Example:

    AlertDialog.Builder adb = new AlertDialog.Builder(context);
    ..... //set up title, message, etc
    adb.setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            callback.invoke(origin, false, false);
        }
    });
    adb.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            callback.invoke(origin, true, false);
        }
    });
    adb.show();
    

    0 讨论(0)
提交回复
热议问题