Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid + phonegap +package manager
    primarykey
    data
    text
    <p>I need to write a cordova plugin to retrive the application name, version code and version name using for Android application. Please Respond ASAP... Thanks in Advance :)</p> <p>Here is my Code....getting Invalid Action Error Message.</p> <p>In <strong>My.js</strong></p> <pre><code>var AppInfo = function() {}; AppInfo.prototype.getVersionName = function(successCallback, failureCallback) { return cordova.exec( successCallback, failureCallback, 'AppInfo', 'GetVersionName', [] ); }; </code></pre> <p>In <strong>AppInfo.java</strong> <em>(Plugin)</em></p> <pre><code>package com.cordova.plugin.appInfo; import org.json.JSONArray; import org.json.JSONException; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.PluginResult; import org.apache.cordova.api.PluginResult.Status; public class AppInfo extends CordovaPlugin { public final String ACTION_GET_VERSION_NAME = "GetVersionName"; Context ctx; public PluginResult execute(String action, JSONArray args, String callbackId) { ctx = cordova.getContext(); PluginResult result = new PluginResult(Status.INVALID_ACTION); PackageManager packageManager = this.ctx.getPackageManager(); if(action.equals(ACTION_GET_VERSION_NAME)) { try { PackageInfo packageInfo = packageManager.getPackageInfo( this.ctx.getPackageName(), 0); result = new PluginResult(Status.OK, packageInfo.versionName); } catch (NameNotFoundException nnfe) { result = new PluginResult(Status.ERROR, nnfe.getMessage()); } } return result; } } </code></pre> <p>In <strong>.html</strong></p> <pre><code>&lt;script&gt; function onDeviceReady () { $('#send').bind('click', function () { alert('Hello World'); window.applicationInfo = new AppInfo(); window.applicationInfo.getVersionName( function(versionName){ alert("versionName" + versionName); }, function (errorMessage){ alert("Error is "+errorMessage); } ); }); } document.addEventListener("deviceready", onDeviceReady, false); &lt;/script&gt; </code></pre> <p>and finally setting permission and Plugin in plugin.xml</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload