0

This is based on the Metaio sdk, but not sure the problem is dependant of it. I have created a basic AREL based Android app, using the Creator. On detection of marker I would like to load a url in a webview.

However when the marker is detected, I get the dialog of choosing what browser to open the url in.

How can I override that and make it open inside a webview in my app?

I tried using public boolean shouldOverrideUrlLoading(WebView view, String url) but it does not get called.

How can I make sure I get all the urls that are attempted to open by an Activity? so I can direct the calls to a webview..

In my activity I have this inside onCreate:

mWebView = (WebView) findViewById(R.id.webview); mWebView.setWebViewClient(new WebViewHandler());

and this outside onCreate:

class WebViewHandler extends WebViewClient {

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) 
    {
        Log.d("LEE","ping1!!!!!"+url);
        mProgress.setVisibility(View.VISIBLE);
    }

    @Override
    public void onPageFinished(WebView view, String url) 
    {
        Log.d("LEE","ping2!!!!!"+url);
        mProgress.setVisibility(View.GONE);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    {
        Log.d("LEE","Triggered url: !!!!!"+url);
    }
}
Fernando Gallego
  • 4,064
  • 31
  • 50
George Mincila
  • 529
  • 5
  • 17

3 Answers3

0

You have a mistake in your override. You should be returning false at the end of shouldOverrideUrlLoading(). This will allow your WebView to handle the request instead of the system.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • It has return true / false based on some conditions. I have not pasted here. The problem is that I do not get the Log "Triggered url" so it is not called at all, right? – George Mincila Nov 19 '13 at 12:08
  • Post the bare bones of your conditions with some minor comments for explanations. – JoxTraex Nov 19 '13 at 12:09
  • I removed all and left just Log.d*() and return:false inside shouldOverrideUrlLoading() but still nothing. It does not get called... What am I missing? – George Mincila Nov 19 '13 at 12:20
  • Did you remember to set the webview to load the url from the shouldOverride... method? – JoxTraex Nov 19 '13 at 20:39
0

Have you tried to do it directly in AREL using arel.Media.openWebsite(url, false);

http://dev.junaio.com/arel/documentationArelJS/symbols/arel.Media.html#.openWebsite

You can edit arel code from creator directly

Fernando Gallego
  • 4,064
  • 31
  • 50
0

I solved it by overriding openWebsite() inside ARELInterpreterCallback like this...

//ARELViewActivity.java
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;

    import com.metaio.cloud.plugin.view.WebViewActivity;
    import com.metaio.sdk.ARELActivity;
    import com.metaio.sdk.jni.IARELInterpreterCallback;


    public class ARELViewActivity extends ARELActivity {

        protected ARELInterpreterCallback myARELCallback;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            myARELCallback = new ARELInterpreterCallback();

            if (mARELInterpreter != null)
                mARELInterpreter.registerCallback(myARELCallback);
        }

        @Override
        protected int getGUILayout() {
            return 0;
        }

        class ARELInterpreterCallback extends IARELInterpreterCallback
        {

            @Override
            public void onSDKReady()
            {
                loadARELScene();
            }

            @Override
            public boolean openWebsite(String url, boolean openInExternalApp){

                //url is set with arel.Media.openWebsite("template://item#", false); inside logic.js
                if (url.contains("template://")) {
                    if (url.contains("item1")) {
                        urlSub = url.substring(14, url.length());
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Intent i = new Intent(ARELViewActivity.this, WebViewActivity.class);
                                i.putExtra(getPackageName() + ".URL", "http://www.google.com.mx");
                                startActivity(i);
                            }
                        });

                        return true;

                    } else {
                        urlSub = url.substring(14, url.length());
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Intent i = new Intent(ARELViewActivity.this, WebViewActivity.class);
                                i.putExtra(getPackageName() + ".URL", "http://www.yahoo.com.mx");
                                startActivity(i);
                            }
                        });

                        return true;
                    }

                } else {
                    return false;
                    //return super.openWebsite(url, openInExternalApp);
                }

            }
        }

    }
dianakarenms
  • 2,609
  • 1
  • 22
  • 22