我正在加载一个我无法控制的外部website
,下载buttons
或打算在其他地方打开的链接,例如.ics或.pdf文件没有任何效果或动作,比如在app
本身打开它默认的application
。这是代码
onDeviceReady: function() {
var openWindow = function() {
var ref = cordova.InAppBrowser.open('https://www.example.com', '_blank', 'location=yes,zoom=no,toolbar=no,enableViewportScale=yes');
ref.addEventListener('exit', function(event) { navigator.app.exitApp()
navigator.notification.activityStart("", "loading");
});
var loadStop = function(event) {
navigator.notification.activityStop();
ref.removeEventListener('loadstop', loadStop);
};
ref.addEventListener('loadstop', loadStop);
};
我以某种方式找到了一种方法来在Android上,插件,inappbrowser.java,在这条路径上:\ platforms \ android \ app \ src \ main \ java \ org \ apache \ cordova \ inappbrowser
在这个方法上,我添加了更多的参数来获取.pdf和.ics文件
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
if (url.endsWith(".pdf")){
try{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.setPackage("com.android.chrome");
cordova.getActivity().startActivity(intent);
return true;
}catch(android.content.ActivityNotFoundException e){
LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString());
}
} else if (url.contains("/icsdownload/")){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
cordova.getActivity().startActivity(intent);
}
}
我还指定了要打开的特定包。我可以邀请ios部分的帮助