3
我有一個webview加載一個本地html頁面,我需要知道它何時完成加載,所以我使用onPageFinished()這個函數立即發射,但由於某種原因,它工作正常在網站上,例如google.co.uk。android本地webview OnPageFinished觸發遲
public class TestwebviewActivity extends Activity {
/** Called when the activity is first created. */
WebView webview = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
Log.d("Webview", "created");
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient()
{
public void onPageFinished(WebView view, String url)
{
Log.d("Webview", "Finished Loading");
Picture picture = view.capturePicture();
Bitmap b = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
picture.draw(c);
FileOutputStream fos = null;
try {
fos = new FileOutputStream("/sdcard/google_" + System.currentTimeMillis() + ".jpg");
if (fos != null)
{
b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.close();
Log.d("Webview", "Image Created");
}
} catch(Exception e)
{
//...
}
}
});
webview.loadUrl("file:///android_asset/htmlpage.html");
}
}
這只是發生,因爲升級到Android 3.2 - 以前在2.3
任何人都遇到同樣的問題或者有什麼建議?
如果有人可以幫忙,謝謝。
我有這個問題爲好,沒有人似乎爲它提供答案,甚至不與100賞金! – TacB0sS
看看這是否解決了它...我們剛剛想出了它:http://android-know-how-to.blogspot.co.il/2013/08/android-webview-javascript-onpagefinish.html – TacB0sS