想了解CordovaWeb视图缓存清除在android中的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于webview清除缓存的相关问题,此外,我们还将为您介绍关于android–Cordo
想了解Cordova Web视图缓存清除在android中的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于webview清除缓存的相关问题,此外,我们还将为您介绍关于android – CordovaWebView:TIMEOUT ERROR、android – Cordova:如何使用cordova-cli为每个平台设置不同的包名?、android – Web视图不加载重定向网址、android – 为什么CordovaWebViewClient不再在Cordova 6中工作了的新知识。
本文目录一览:- Cordova Web视图缓存清除在android中(webview清除缓存)
- android – CordovaWebView:TIMEOUT ERROR
- android – Cordova:如何使用cordova-cli为每个平台设置不同的包名?
- android – Web视图不加载重定向网址
- android – 为什么CordovaWebViewClient不再在Cordova 6中工作了
Cordova Web视图缓存清除在android中(webview清除缓存)
我试图清除存储在使用cordova webview的android应用程序中的缓存.
我试过cordovaWebView.clearCache(true);也尝试过
public void deleteCache(Context context) {
Log.i("Utility", "deleting Cache");
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception e) {
Log.e("Utility", " exception in deleting cookies");
}
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
} else if (dir != null && dir.isFile()) {
dir.delete(); // delete the file INSIDE the directory
}
Log.i("Utility", "deleting Cache " + dir.delete());
return true;
}
但两者都没有用.
我可以得到任何解决方案,因为在Web视图中用户使用登录,因此我们需要在第二次加载应用程序时清除缓存.
解决方法:
我正在使用“cordova-plugin-cache-clear”插件
https://github.com/anrip/cordova-plugin-cache-clear
要使用该插件,只需调用window.CacheClear(success,error);
它清理webView缓存.
android – CordovaWebView:TIMEOUT ERROR
我也试过了
super.setIntegerProperty("loadUrlTimeoutValue",10000);
但它只是花时间,在那之后,同样的“CordovaWebView:TIMEOUT ERROR!”来了.
请为我提供适当的解决方案.
解决方法
//code executed after the loading of the page (if your using jquery) $(function() { //if this method is too heavy and takes too long to execute,it will trigger the TIMEOUT ERROR. doSomeStuff(); });
不想在此方法上添加超时以便让应用程序启动,然后启动繁重的脚本(您可能希望显示加载图像或类似的东西).
代码段:
//code executed after the loading of the page $(function() { //in mobile environment,this timeout leaves time for the app to launch before we start any heavy process. setTimeout(function(){ doSomeStuff(); },100); });
android – Cordova:如何使用cordova-cli为每个平台设置不同的包名?
由于iOS和Android应用程序是使用PhoneGap 2.x创建的,因此我有两个独立的项目(即iOS项目和Android项目).这些项目具有HTML / CSS / JavaScript资产的共享www目录(使用符号链接).当我升级到Cordova 4.0时,我可以拥有一个Cordova项目,并使用Cordova CLI为platforms目录中的每个平台创建项目.
用于Cordova中每个平台的包名称是在共享的config.xml文件中设置的. Cordova CLI使用config.xml中设置的包名称来执行perpare,build和add platform命令.
不幸的是,用于PhoneGap 2.x应用程序的软件包名称并不相同(即Android应用程序的软件包名称与iOS应用程序的软件包名称不同).
例如:Android应用程序的软件包名称类似于com.example.applongname,但iOS应用程序的软件包名称类似于com.example.AppShortName.包名称的开头(即反向公司域名)对于每个应用程序是相同的,但应用程序名称不同. iOS应用程序名称还包含大写字母.
我需要保留用于初始PhoneGap 2.x版本的软件包名称,以便可以更新应用程序(即最终用户可以接收更新,以替换他们现有的应用程序安装).
如何在不创建两个单独项目的情况下为每个平台设置包名?
解决方法
<widget id="com.company.app" android-packageName="com.company.androidapp" ios-CFBundleIdentifier="com.company.iosapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
有关详细信息,请参阅我的other答案.
android – Web视图不加载重定向网址
webview的代码是:
webView = (WebView) findViewById(R.id.simpleWebView); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient()); if(getIntent().getStringExtra("url")!=null){ loadLink(getIntent().getStringExtra("url")); }else{ Toast.makeText(WebViewActivity.this,"Please try again later!",Toast.LENGTH_SHORT).show(); finish(); }
解决方法
public class Main extends Activity { private WebView webview; private static final String TAG = "Main"; private ProgressDialog progressBar; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestwindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); this.webview = (WebView)findViewById(R.id.webview); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); progressBar = ProgressDialog.show(Main.this,"WebView Example","Loading..."); webview.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view,String url) { Log.i(TAG,"Processing webview url click..."); view.loadUrl(url); return true; } public void onPageFinished(WebView view,"Finished loading URL: " +url); if (progressBar.isShowing()) { progressBar.dismiss(); } } public void onReceivedError(WebView view,int errorCode,String description,String failingUrl) { Log.e(TAG,"Error: " + description); Toast.makeText(activity,"Oh no! " + description,Toast.LENGTH_SHORT).show(); alertDialog.setTitle("Error"); alertDialog.setMessage(description); alertDialog.setButton("OK",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { return; } }); alertDialog.show(); } }); webview.loadUrl("http://www.google.com"); } }
你的main.xml布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <WebView android:id="@string/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" /> </LinearLayout>
android – 为什么CordovaWebViewClient不再在Cordova 6中工作了
我已经编写了自定义webviewclient类来覆盖cordova 3.7中的onPageStarted,onPageFinished等,它工作正常.
在下面的代码中,我已经将www目录托管到Web服务器并从那里交互cordova插件(条形码扫描器,nfc,蓝牙等).
public class MainActivity extends CordovaActivity {
private WebView webView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.init();
loadUrl("https://example.com");
}
public class CustomCordovaWebViewClient extends CordovaWebViewClient {
public CustomCordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) {
super(cordova, view);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.i("CSP Log", "onPageStarted: " + url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.i("CSP Log", "onPageFinished: " + url);
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
super.doUpdateVisitedHistory(view, url, isReload);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
}
}
一年后,我将项目从cordova 3.7迁移到cordova 6,但我发现上面的代码像CordovaWebViewClient一样被破坏,super.onPageStarted等无法解析符号.我也尝试过CordovaWebViewImpl并迷惑自己.
在google上搜索了很多我发现的解决方案,这些解决方案主要在2011-14中给出,不适用.我找不到cordova文档有用.
解决方法:
它被SystemWebViewClient取代
你应该做这样的事情:
SystemWebView wv = (SystemWebView)appView.getView();
wv.setWebViewClient(new SystemWebViewClient((SystemWebViewEngine)appView.getEngine()){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.i("CSP Log", "onPageStarted: " + url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.i("CSP Log", "onPageFinished: " + url);
}
@Override
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload){
super.doUpdateVisitedHistory(view, url, isReload);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
关于Cordova Web视图缓存清除在android中和webview清除缓存的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于android – CordovaWebView:TIMEOUT ERROR、android – Cordova:如何使用cordova-cli为每个平台设置不同的包名?、android – Web视图不加载重定向网址、android – 为什么CordovaWebViewClient不再在Cordova 6中工作了等相关内容,可以在本站寻找。
本文标签: