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 6834441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:06:44+00:00 2026-05-26T23:06:44+00:00

I developed an Android PhoneGap Plugin. The plugin is successfully getting called, but the

  • 0

I developed an Android PhoneGap Plugin. The plugin is successfully getting called, but the callback is not getting invoked. I have no idea where I have missed anything.

Does anybody have any idea as to what could be wrong when the callback are not getting invoked?

Following is my code:

JS File Contents:

var SharedPreferencePlugin = function() {};

SharedPreferencePlugin.prototype.getvalues = function(content, success, fail) {
    return PhoneGap.exec( 
        function(args) {
            console.log("success called from plugin's js file");    
        }, 
        function(args) { 
            console.log("failure called from plugin's js file");
        }, 
        'SharedPreferencePlugin', 
        'getvalues', 
        [content]
    );
};

SharedPreferencePlugin.prototype.update = function(itemName, success, fail) {
    return PhoneGap.exec( 
        function(args) {
            console.log("success called from plugin's js file");    
        }, 
        function(args) { 
            console.log("failure called from plugin's js file");
        }, 
        'SharedPreferencePlugin', 
        'update', 
        [itemName]
    );
};

PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin('SharedPreferencePlugin', new SharedPreferencePlugin());
});

Java file:

public class SharedPreferencePlugin extends Plugin{

    public static final String GET_ACTION = "getvalues";
    public static final String UPDATE_ACTION = "update";
    static Context staticContext = MainActivity.staticContext;
    SharedPreferences dataStorage = staticContext.getSharedPreferences(MainActivity.PREFS_NAME, 0);

    public PluginResult execute(String action, JSONArray data, String callbackId)
    {
        Log.d("SharedPreferencePlugin", "Plugin Called with action: " + action);
        PluginResult result = null;
        if(action.equals(GET_ACTION))
        {
            Log.d("SharedPrferencePlugin", "inside if for 'getvalues'");
            JSONArray savedData = getPreferences();
            Log.d("SharedPreferencePlugin", "Data: " + savedData);
            result = new PluginResult(Status.OK, savedData);
        }
        else if(action.equals(UPDATE_ACTION))
        {
            try
            {
                updateSharedPreferences(data.getJSONObject(0).getString("itemName"));
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("status", "success");

                result = new PluginResult(PluginResult.Status.OK, jsonObject);
            }
            catch(JSONException ex)
            {
                Log.d("SharedPreferencePlugin", "Got JSONException: " + ex.getMessage());
                result = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
            }
        }
        else
        {
            result = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
            Log.d("SharedPreferencePlugin", "Invalid action: " + action + " obtained.");
        }
        return result;
    }

    public void updateSharedPreferences(String itemName)
    {
        Log.d("SharedPreferencePlugin", "Inside updateSharedPreferences, value passed: " + itemName);
        SharedPreferences tmpPreferenceReference = staticContext.getSharedPreferences(MainActivity.PREFS_NAME, 0);
        SharedPreferences.Editor editor = tmpPreferenceReference.edit();

        if(itemName.equals(tmpPreferenceReference.getString(MainActivity.NAME_ITEM1, "")))
        {
            Integer tmpInt = Integer.parseInt(tmpPreferenceReference.getString(MainActivity.QUANTITY_ITEM1, "0")) - 1;
            editor.putString(MainActivity.QUANTITY_ITEM1, tmpInt.toString());
        }
        editor.commit();
    }

    protected JSONArray getPreferences()
    {
        ArrayList<String> arrItemNames = new ArrayList<String>();
        ArrayList<String> arrItemQuantities = new ArrayList<String>();

        arrItemNames.add(0, dataStorage.getString(MainActivity.NAME_ITEM1, ""));
        arrItemNames.add(1, dataStorage.getString(MainActivity.NAME_ITEM2, ""));
        arrItemQuantities.add(0, dataStorage.getString(MainActivity.QUANTITY_ITEM1, ""));
        arrItemQuantities.add(0, dataStorage.getString(MainActivity.QUANTITY_ITEM2, ""));

        //-------------------------------------------------------------------
        ArrayList<ArrayList> tempArrayList = new ArrayList<ArrayList>();
        tempArrayList.add(arrItemNames);
        tempArrayList.add(arrItemQuantities);

        JSONArray jsonData = new JSONArray(tempArrayList);
        //-------------------------------------------------------------------

        return jsonData;
    }
}

HTML CODE TO CALL THE PLUGIN:

function test()
            {
                console.log("Test called");
                window.plugins.SharedPreferencePlugin.getvalues({},
                    function() { // Success function
                        console.log("success called");
                    }, 
                    function() {  // Failure function
                        console.log('Share failed');
                    }
                );
            }

Any help is highly appreciated.

Thanks.

  • 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-05-26T23:06:45+00:00Added an answer on May 26, 2026 at 11:06 pm

    Thank you guys for your answers.

    Since the problem was not getting solved, I recreated a new Test project and went step by step to ensure that each little piece of code works properly and slowly moved to the desired goal for the plugin.

    I finally got it working with the new project I created and writing the Plugin again from scratch.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed an Android application that has 1 process and 2 services. But
I'm trying to login to facebook via phonegap on android phone, but it's not
I followed their how-to: Phonegap Start Phonegap wiki I have succesfully installed the android
I have developed android application. Now it is time to give it to the
My self-developed android app create 7 items on Device with the same name, but
I have developed an android application, which uses image files and strings from the
I have developed a android application which I want to test on multiple devices
I have created a simple application in android [PhoneGap] [Eclipse] {Sorry for this convention
I have developed android application named VMS.I have to get messages from the webservice.The
I have a mobile app that I developed using PhoneGap (and html/css/javascript) and there

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.