Start a new topic

Cannot call activity method in JS

Cannot call activity method in JS


Hi all,

I'm a new wikitude dev, I have a problem when call a method in Activity from JS file.

Here is my code:

- In JS:

createActivityButton: function createActivityButtonFn(className, size, options) {
        options.onClick = function startTestActivity() {
            document.location = "architectsdk://startTestActivity?className="+className;   
            //AR.context.openInBrowser(className);
        };
        return new AR.ImageDrawable(this.imgButton, size, options);
    },

- In Activity (implemented ArchitectUrlListener):

@Override
    public boolean urlWasInvoked(String url) {
        //parsing the retrieved url string
        List<NameValuePair> queryParams = URLEncodedUtils.parse(URI.create(url), "UTF-8");
        String className = "";
        // getting the values of the contained GET-parameters
        for(NameValuePair pair : queryParams) {
           if(pair.getName().equals("className")) {
               className = pair.getValue();
           }
        }
        Log.i(this.getLocalClassName(), className + " yes");
        startTestActivity(className);
        return true;
    }
    
    private void startTestActivity(String className) {
        try {
            Intent intent = new Intent(this, Class.forName(className));
            startActivity(intent);
        } catch (ClassNotFoundException e) {
            Log.e(this.getPackageName(), e.getCause().getMessage());
        }
    }

Thanks in advance!

Hi,

are you calling registerUrlListener(ArchitectView.ArchitectUrlListener listener) to register the listener, it won't be called otherwise. If you already did that, is the method urlWasInvoked called? Addtionally you can check if your javascript code by testing it in a desktop browser using the ade.js (included with the SDK). This allows you to use browser debugging tools to investigate any javascript problems.

Let me know if that helped.
Login or Signup to post a comment