zontrakulla zontrakulla - 1 year ago 215
Android Question

Unable to open asset URL: file:///android_asset/activity_a

I just began android coding and I'm still learning from my mistakes. I use

to load internal html pages and I want to open another activity window which will be a
barcode scanner
by clicking a hyperlink on
. However I get this error

Unable to open asset URL: file:///android_asset/activity_a://qrcodeactivity


<activity android:name="qrcodeactivity" >
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="activity_a" />


<a href="activity_a://qrcodeactivity">Activity A</a>

MyWebClient Java

private class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {

if (url.equals("activity_a://qrcodeactivity")) {
Intent intent = new Intent(getContext(), qrcodeactivity.class);
return true; // Handle By application itself
} else {

if (loader.equals("pull")) {
} else if (loader.equals("dialog")) {
if (!pd.isShowing()) {
} else if (loader.equals("never")) {
Log.d("WebView", "No Loader selected");

return true;


public void onPageFinished(WebView view, String url) {
if (pd.isShowing()) {

if (swipeContainer.isRefreshing()) {

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
webView.loadUrl("file:///android_asset/" + getString(R.string.error_page));


Answer Source

WebView has no idea what activity_a:// is. Apparently, it is treating it as a relative reference, as if it were activity_a/.

Since you are using this in a WebView, there is no need to invent your own scheme. You are checking the entire URL in shouldOverrideUrlLoading().

So, you could change the HTML to:

<a href="/qrcodeactivity">Activity A</a>

and change your if to match:

if (url.equals("file:///qrcodeactivity")) {

And, you can get rid of the <intent-filter> from your <activity>. Having that is dangerous, anyway, as you are indicating that any app on the device can start that activity, as an activity with an <intent-filter> is exported.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download