简单的webview示例捕获安全异常

时间:2013-08-22 06:14:49

标签: android webview

  

我有一个简单的webview代码,虽然运行代码有效但在logcat中显示错误'抓住安全异常'。这是什么意思?

WebActivity.java

public class WebActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
        WebSettings webSettings = mainWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mainWebView.setWebViewClient(new MyCustomWebViewClient());
        mainWebView.loadUrl("http://google.com");
        mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    }
    private class MyCustomWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
            }
        }
    }
  

logcat的

08-22 11:37:01.569: E/geolocationService(537): Caught security exception registering for location updates from system. This should only happen in DumpRenderTree.

2 个答案:

答案 0 :(得分:3)

您需要在清单中添加此内容。

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

答案 1 :(得分:0)

此链接有密钥 http://cordova.apache.org/docs/en/2.5.0/cordova_device_device.md.html

我正在开发Android - Phonegap

我添加了

- &GT;应用程序/ RES / XML / config.xml中

&LT;插件名称=&#34;设备&#34;值=&#34; org.apache.cordova.Device&#34; /&GT;

- &GT;应用程序/ AndroidManifest.xml中

&LT; uses-permission android:name =&#34; android.permission.READ_PHONE_STATE&#34; /&GT;

并且工作正常

PS:也许它与这个答案相同 Using navigator.geolocation.getCurrentPosition in WebView on Android 2.0+ (PhoneGap related)