安卓:单击在Web视图页面链接 [英] Android : click link in a page within web view

查看:152
本文介绍了安卓:单击在Web视图页面链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经包含在Android的web视图的Web应用程序,并且在该网页中的链接,打开其他网站,链接被点击时,它工作正常,第一次点击,点击第二次的网站然而,当没找到,

在code是:

  @覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){

    如果(url.contains(某些网站)){
     意图I =新
         意图(Intent.ACTION_VIEW,Uri.parse(URL));
     startActivity(ⅰ);
         返回true;
    } 其他 {
    view.loadUrl(URL);
    返回false;
   }
}
 


@THelper和@mikegr,感谢您的答复,

其实在我的情况,我有一个模式面板(JSF)在我的web应用程序,其中包含一些按钮,单击按钮时我使用的JavaScript的window.open()方法,它在桌面浏览器工作正常打开其他网站,但,当我包裹内的Andr​​oid的WebView该web应用程序,一切工作正常,只是当我第一次点击这个按钮我可以使用外部浏览器打开其他网站,但在第二次点击web视图试图在web视图中打开此othersite代替我得到的网站没有发现与其他网站的整个URL的外部浏览器和,这种情况甚至当我注销并重新登录作为启动的应用程序仍在运行。

也是我的情况下,一段时间后,当应用程序处于空闲状态,我得到了黑屏。

我冲浪通过网络,发现呈三角问题,但这并没有帮助,这里是链接:

http://groups.google.com/group/android-for-beginners/browse_thread/thread/42431dd1ca4a9d98

处理在web视图链接,

任何帮助和想法将是对我很大的帮助,这需要花费很长的时间我,

因为我想显示在Web视图我的web应用程序,我只有一个活动,其中包含code这样

  @覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);

如果(savedInstanceState!= NULL){
        //使得当启动器被点击,而应用程序是
           //运行时,应用程序不会从begnining开始
} 其他 {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    的setContentView(R.layout.main);

    //显示ProgressDialog在此线程
        this.progressDialog = ProgressDialog.show(这一点,普莱斯等等..,加载,真正的);

    浏览器=(web视图)findViewById(R.id.webview);
    browser.getSettings()setJavaScriptEnabled(真)。

    browser.setWebViewClient(新WebViewClient(){

        公共无效onPageFinished(web视图查看,字符串URL){
                Log.i(TAG,加载完成URL:+网址);

                如果(progressDialog.isShowing()){
                    progressDialog .dismiss();
                }
            }


@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){

如果(url.contains(某些网站)){
     意图I =新
     意图(Intent.ACTION_VIEW,Uri.parse(URL));
     startActivity(ⅰ);
             返回true;
} 其他 {
        view.loadUrl(URL);
    返回true;
}
 }
});
browser.loadUrl(mysite的);
}
}
 

解决方案

onPageStarted 为我工作。不得不调整它一下,因为当web视图首次呈现过该方法被调用,我想只在的onClick旗帜的JavaScript的执行。

我是用模拟的自定义页面的一面旗帜,所以当 ad.html 被渲染,我避免了 startActivity 。否则,它会启动新的浏览器窗口。

  WebViewClient newWebClient =新WebViewClient(){
        @覆盖
        公共无效onPageStarted(web视图查看,字符串URL,位图图标){
            // TODO自动生成方法存根
            super.onPageStarted(查看,网址,网站图标);
            如果(url.equals(@的http://xxxx.ad.html))
            。view.getContext()startActivity(新意图(Intent.ACTION_VIEW,Uri.parse(URL)));
        }
    };
 

I have included a web application within android web view , and there is a link in the webpage which opens some other site , when the link is clicked it works fine for the first click, however when clicked for the second time the website is not found ,

the code is :

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

    if (url.contains("some site ")) {
     Intent i = new
         Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(i);
         return true;
    } else {
    view.loadUrl(url);
    return false;
   }
}


@THelper and @mikegr, thanks for the reply,

Actually in my case i have a modal panel (JSF) in my web application which contains some buttons, on clicking the button i am opening some other site using javascript window.open() method which works fine in desktop browser, however, when i wrap this web application within android webview, everything works fine except when i first click this button i'm able to open the other site using the external browser, however on second click the webview tries to open this othersite within the webview instead of the external browser and i get website not found with the entire URL of the other site, this happens even when i logout and login again as the application launched is still running.

also in my case after sometime when the application is idle i get the black screen.

i surfed through the net and found simillar issue but that didn't help either , here is the link:

http://groups.google.com/group/android-for-beginners/browse_thread/thread/42431dd1ca4a9d98

handling links in a webview ,

any help and ideas would be very helpful for me, this is taking too long for me,

since i'm trying to display my web application in the web view, i have only one activity, which contains code like this

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (savedInstanceState != null) {
        // so that when launcher is clicked while the application is 
           // running , the application doesn't start from the begnining
} else {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);

    // Show the ProgressDialog on this thread
        this.progressDialog = ProgressDialog.show(this, "Pleas Wait..", "Loading", true);

    browser = (WebView) findViewById(R.id.webview);
    browser.getSettings().setJavaScriptEnabled(true);

    browser.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
                Log.i(TAG, "Finished loading URL: " +url);

                if (progressDialog.isShowing()) {
                    progressDialog .dismiss();
                }
            }


@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

if (url.contains("some site")) {
     Intent i = new
     Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(i);
             return true;
} else {
        view.loadUrl(url);
    return true;
}
 }
});
browser.loadUrl("mysite");
}
}

解决方案

onPageStarted worked for me. Had to tweak it a bit, as that method is called when the webview is first rendered too, and I wanted to only execute it on the onClick of the banner's javascript.

I was simulating a banner with a custom page, so when the ad.html was being rendered, I avoided the startActivity. Otherwise, it launches the new browser window.

WebViewClient newWebClient = new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
            if(!url.equals("http://xxxx.ad.html"))
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        }
    };

这篇关于安卓:单击在Web视图页面链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆