gpt4 book ai didi

Android + PhoneGap拦截URL(相当于iOS的shouldStartLoadWithRequest)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:53:34 24 4
gpt4 key购买 nike

我的 PhoneGap 封装的、本地托管的 Sencha Touch 应用程序制作了一些假的 URL 回调来与 native 封装器通信。 (即 app_callback://do_function_a)。

在 iOS 中我实现了以下内容

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

检查 app_callback:// URL,调用 native 函数并返回 NO(以停止实际发生的导航)。

Android 中是否有我可以实现的等效项?

提前致谢!

最佳答案

@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");}

这适用于 API 版本 9-17 重要的是还添加了 onLoadResource

关于Android + PhoneGap拦截URL(相当于iOS的shouldStartLoadWithRequest),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12601491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com