'Get location from website using web view for Android
I am trying to show the pop up for allowing using of location in a web view for my android app, but whenever I visit a page that should use the location, the pop up for requesting using of locations never shows up and therefore the location coordinates never show up.
Any idea what I am missing?
web.setWebChromeClient(new WebChromeClient(){
@Override
public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) {
final boolean remember = true;
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Locations");
builder.setMessage(origin + " Would like to use your Current Location").setCancelable(true).setPositiveButton("Allow",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
// origin, allow, remember
callback.invoke(origin, true, remember);
}
})
.setNegativeButton("Don't Allow",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
// origin, allow, remember
callback.invoke(origin, false, remember);
}
});
AlertDialog alert = builder.create();
alert.show();
super.onGeolocationPermissionsShowPrompt(origin, callback);
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
