我正在编写一个主要使用Javascript连接到网站的基本移动包装器。此站点有一个登录表单,尝试访问相关设备的地理位置。当在模拟器上运行时,没有提示允许位置(这在我的脑海中是有意义的,因为PC具有物理位置和外部IP地址等)并且GeoLocation只是没有问题,这对我来说建议代码至少是权限和webView设置的功能。在启用了位置服务的设备上运行时,即使我提示并允许其位置,该网站也无法解析我的位置。
webView和设置如下所示,Android Manifest如下所示。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wView = (WebView) findViewById(R.id.activity_main_webview);
WebView.setWebContentsDebuggingEnabled(true);
wView.setWebChromeClient(new WebChromeClient(){
@Override
public void onGeolocationPermissionsShowPrompt(final String origin,
final GeolocationPermissions.Callback callback) {
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage( origin + " would like to use your current location" );
builder.setNegativeButton( "Don't Allow", new DialogInterface.OnClickListener() {
@Override
public void onClick( DialogInterface dialog, int which ) {
callback.invoke( origin, false, false );
dialog.dismiss();
}
} );
builder.setPositiveButton( "Okay", new DialogInterface.OnClickListener() {
@Override
public void onClick( DialogInterface dialog, int which ) {
callback.invoke( origin, true, false );
dialog.dismiss();
}
});
}
});
wView.getSettings().setJavaScriptEnabled(true);
wView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wView.getSettings().setGeolocationEnabled(true);
String url = BuildConfig.HOST_URL;
//String postData = "username="+ URLEncoder.encode(user,"UTF-8")+"&password="+URLEncoder.encode(password,"UTF-8");
//Log.e("TEST","postData " + postData);
wView.loadUrl(url);
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.toteireland.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="Tote Ireland"
android:theme="@style/AppTheme"
>
<activity
android:name="com.toteireland.app.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这是权限的正确位置吗?