我剛開始使用android編碼,我仍然從錯誤中學習。我使用WebView
加載內部html頁面,我想要打開另一個活動窗口,該窗口將是barcode scanner
,方法是單擊webview
上的超鏈接。不過,我得到這個錯誤無法打開資源URL:file:/// android_asset/activity_a
Unable to open asset URL: file:///android_asset/activity_a://qrcodeactivity
AndroidManifest.xml中
<activity android:name="qrcodeactivity" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="activity_a" />
</intent-filter>
</activity>
的index.html
<a href="activity_a://qrcodeactivity">Activity A</a>
MyWebClient的Java
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals("activity_a://qrcodeactivity")) {
Intent intent = new Intent(getContext(), qrcodeactivity.class);
startActivity(intent);
return true; // Handle By application itself
} else {
view.loadUrl(url);
if (loader.equals("pull")) {
swipeContainer.setRefreshing(true);
} else if (loader.equals("dialog")) {
if (!pd.isShowing()) {
pd.show();
}
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");
}
return true;
}
}
@Override
public void onPageFinished(WebView view, String url) {
if (pd.isShowing()) {
pd.dismiss();
}
if (swipeContainer.isRefreshing()) {
swipeContainer.setRefreshing(false);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/" + getString(R.string.error_page));
}
}
你好,非常感謝你的回答。我做了你的變化,但我仍然得到相同的錯誤。 file:/// qrcodeactivity找不到 – zontrakulla
@zontrakulla:對不起,我在'if'測試中忘了這個方案。查看更新後的答案。基本上,你的'if'需要匹配'WebView'生成的URL。 – CommonsWare
工作完美!非常感謝。 – zontrakulla