Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:57:34+00:00 2026-06-03T05:57:34+00:00

I have a minor Problem. I’m trying to create a plugin to do some

  • 0

I have a minor Problem. I’m trying to create a plugin to do some heavy
work in an native plugin and also shipping around a limitation in the
web sqlite implementation.
(Database is limited to 5MB, but I need some more).

First of all here’s the Main class that is intended to do the work:

package com.worker.api;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;

public class worker extends Plugin{
    public final String version = "1.0";
    public String callback;
    public worker(){

    }

    public PluginResult execute(String action, JSONArray args, String
                                callbackId) {
        this.callback = callbackId;
        PluginResult r = null;
        try{
            if(action.equals("connectDB")){

            }else if(action.equals("closeDB")){

            }else if(action.equals("query")){
                r = this.query();
            }else if(action.equals("insert")){
                r = this.insert();
            }else if(action.equals("update")){
                r = this.update();
            }else if(action.equals("delete")){
                r = this.delete();
            }else if(action.equals("syncronize")){
                r = this.syncronize();
            }else if(action.equals("getVersion")){
                r = this.getVersion();
            }else{
                r = new PluginResult(Status.INVALID_ACTION);
                r.setKeepCallback(true);
            }
        }catch(JSONException ex){
            r = new PluginResult(Status.JSON_EXCEPTION);
        }
        return r;
    }
    public PluginResult query(){
        return null;
    }
    public PluginResult insert(){
        return null;
    }
    public PluginResult update(){
        return null;
    }
    public PluginResult delete(){
        return null;
    }
    public PluginResult syncronize(){
        return null;
    }
    public PluginResult getVersion() throws JSONException{
        JSONObject obj = new JSONObject();
        obj.put(version,this.version);
        return new PluginResult(Status.OK,obj);
    }
}

At the moment I only implemented the getVersion part as I’m still
doing testing on this

In the plugin.xml I added this:

<plugin name="workerAPI" value="com.worker.api.worker" />

The main js file looks like this:

    var workerApi = function(){}

    var genericSuccess = function(e) {
        alert("Success: " + e.toString());
    };

    var fail = function(e) {
        alert("Failure " + e.toString());
    };

    workerApi.prototype.doAction = function(
            operation,
            argument,
            successFunction,
            failFunction
            ){
        var succ = successFunction ? successFunction : genericSuccess;
        var faic = failFunction ? failFunction : fail;
        return PhoneGap.exec(
                succ,
                faic,
                "workerAPI",
                operation,
                [argument]
        );
    };

    PhoneGap.addConstructor(function() {
        PhoneGap.addPlugin(
                    "workApi",
                    new workerApi()
        );
    });

    var WKapi = {
            "openDB": function(){
                window.plugins.workApi.doAction(
                    "connectDB",
                    null
                );
            },
            "closeDB": function(){
                window.plugins.workApi.doAction(
                    "closeDB",
                    null
                );
            },
            "query": function(arg){
                window.plugins.workApi.doAction(
                    "query",
                    arg
                );
            },
            "insert": function(arg){
                window.plugins.workApi.doAction(
                    "insert",
                    arg
                );
            },
            "update": function(arg){
                window.plugins.workApi.doAction(
                    "update",
                    arg
                );
            },
            "delete": function(arg){
                window.plugins.workApi.doAction(
                    "delete",
                    arg
                );
            },
            "sync": function(arg){
                window.plugins.workApi.doAction(
                    "syncronize",
                    arg
                );
            },
            "version": function(){
                window.plugins.workApi.doAction(
                    "version"
                );
            }
    };

As soon as I execute it, the logger LogCat tells me as error:

Uncaught TypeError: Cannot call methid ‘doAction’ of undefined at
file:///android_asset/www/worker.js:79

I don’t really know what I’m doing wrong.

—–ADDON——

Here’s the codeblock that is part of the index.php

        <script lang="text/javascript">
            document.addEventListener("deviceready", onDeviceReady, false);
            var isRun = false;
            function onDeviceReady() {
                WKapi.version();
            };
        </script>
    </div>
</body>
</html>

I still get Uncaught TypeError: Cannot call method ‘doAction’ …
It happens on this call: window.plugins.workerApi.doAction

If I put the window.plugins.workerApi into a alert it gives me unknown back.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:57:35+00:00Added an answer on June 3, 2026 at 5:57 am

    In your Java class, you are looking for “getVersion”, so that’s what needs to be passed here.

    "version": function(){
        window.plugins.workApi.doAction(
            "getVersion"
            );
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a minor problem guys which I need some help. I have a
I have some minor problem with an SQL query. I have to select data
I have found a minor problem when i install my application on real android
I am working on my minor project. I have to create an image editor
I have a minor problem where my (new) computer tends to completely freeze up.
I have some problem with my java application, I did build it with Eclipse
I have a minor problem, basically I have a hidden input button which is
I'm a PHP newbie, so I have a minor problem functions. I have this
I have the following code which seems to work OK except for a minor
In trying to implement the repository pattern I've run into a minor problem that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.