安卓+ PhoneGap的拦截URL(IOS shouldStartLoadWithRequest相同) [英] Android + PhoneGap intercept URL (equivalent of iOS shouldStartLoadWithRequest)

查看:1296
本文介绍了安卓+ PhoneGap的拦截URL(IOS shouldStartLoadWithRequest相同)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PhoneGap包,本地托管的煎茶触摸应用程序,使得一些假冒的URL回调与本机的包装进行沟通。 (即 app_callback:// do_function_a )。

在我的iOS实现以下

   - (BOOL)web视图:(UIWebView的*)web视图shouldStartLoadWithRequest:(的NSURLRequest *)要求navigationType:(UIWebViewNavigationType)navigationType;
 

请检查 app_callback:// 网​​址,调用本机功能,然后返回NO(停止航行,实际发生的事情)

有没有在Android的等效我能实现?

在此先感谢!

解决方案

  @覆盖
公共无效的onCreate(包savedInstanceState){
    super.setBooleanProperty(showTitle,真正的);
    super.onCreate(savedInstanceState);

    //创建super.appView和DroidGap.java调用的setContentView(根)
    在里面();

    this.appView.clearCache(真正的);
    this.appView.clearHistory();
    this.appView.setWebViewClient(新CordovaWebViewClient(这一点,this.appView){

        @覆盖
        公共WebResourceResponse shouldInterceptRequest(web视图查看,字符串URL){

            Log.d(调试,应该拦截请求+网址);
            //实现你的code
            返回super.shouldInterceptRequest(查看,网址);
        }

        @覆盖
        公共无效onLoadResource(web视图查看,字符串URL){
            Log.d(调试,onLoadResource+网址);
            //实现你的code
            super.onLoadResource(查看,网址);
        }



        @覆盖
        公共无效onPageFinished(web视图查看,字符串URL){
            Log.d(调试,第完了+网址);
            //实现你的code
            super.onPageFinished(查看,网址);
        }


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

            Log.d(调试,应该重写URL加载+网址);
            //实现你的code
            返回super.shouldOverrideUrlLoading(查看,网址);


        }

    }); super.loadUrl(文件:///android_asset/www/index.html);}
 

这是API版本9-17重要的是还添加onLoadResource

My PhoneGap wrapped, locally hosted Sencha Touch app makes some fake URL callbacks to communicate with the native wrapper. (ie. app_callback://do_function_a).

In iOS I implement the following

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

Check for the app_callback:// URLs, call a native function and return NO (to stop navigation actually happening).

Is there an equivalent in Android I can implement?

Thanks in advance!

解决方案

@Override
public void onCreate(Bundle savedInstanceState) {
    super.setBooleanProperty("showTitle", true);
    super.onCreate(savedInstanceState);

    //creates super.appView and calls setContentView(root) in DroidGap.java
    init();

    this.appView.clearCache(true);
    this.appView.clearHistory();  
    this.appView.setWebViewClient(new CordovaWebViewClient(this, this.appView) {

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {

            Log.d("DEBUG", "Should intercept request" +url);
            //Implement your code
            return super.shouldInterceptRequest(view, url);
        }

        @Override
        public void onLoadResource(WebView view, String url) {
            Log.d("DEBUG", "onLoadResource" +url);
            //Implement your code
            super.onLoadResource(view, url);
        }



        @Override
        public void onPageFinished(WebView view, String url) {
            Log.d("DEBUG", "On page finished "+url);
            //Implement your code
            super.onPageFinished(view, url);
        }


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

            Log.d("DEBUG", "should override url loading "+url);
            //Implement your code
            return super.shouldOverrideUrlLoading(view, url);


        }

    });super.loadUrl("file:///android_asset/www/index.html");}

This is for API versions 9-17 Important is also add onLoadResource

这篇关于安卓+ PhoneGap的拦截URL(IOS shouldStartLoadWithRequest相同)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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