Reputation: 355
I'm trying to create and add a plugin to my Cordova application. All the plugin does at this point is return an alert box and a callbackContext with some text. I can successfully call the plugin and return the text when I build the app through the CLI with "cordova run android", but when I convert my application to APK through PhoneGap Build the plugin no longer works. Does anyone know why this is happening? I've read the Cordova and PhoneGap documentation extensively and have used code from published PhoneGap plugins as guidelines, but can't seem to figure this out.
Any help is greatly appreciated.
plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.assettagz.cordova.plugin.scan"
version="1.0.0">
<js-module src="www/Scan.js" name="Scan">
<clobbers target="scan" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Scan" >
<param name="android-package" value="com.assettagz.cordova.plugin.scan.Scan"/>
</feature>
</config-file>
<source-file src="src/android/Scan.java" target-dir="src/com/assettagz/cordova/plugin/scan" />
</platform>
Plugin Javascript File:
var exec = require('cordova/exec');
var Scan =
{
read : function( success, error )
{
exec(success, error, "Scan", "read", [])
}
}
module.exports = Scan;
Plugin Java File:
package com.assettagz.cordova.plugin.scan;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Message;
import android.util.Log;
public class Scan extends CordovaPlugin {
private CallbackContext callbackContext;
/**
* Constructor.
*/
public Scan() {
}
@Override
public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException
{
if( action.equals("read") )
{
AlertDialog.Builder builder1 = new AlertDialog.Builder(cordova.getActivity());
builder1.setMessage("success");
AlertDialog alert11 = builder1.create();
alert11.show();
this.callbackContext = callbackContext;
callbackContext.success("success");
return true;
}
return false;
}
index.html:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title></title>
<link rel="stylesheet" href="vendors/jquery.mobile/jquery.mobile-1.4.3.min.css">
<link rel="stylesheet" href="css.css" />
<script src="vendors/jquery/jquery.js"></script>
<script src="vendors/jquery.mobile/jquery.mobile-1.4.3.min.js"></script>
<script src="vendors/angular.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script>
function fireItUp() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
jQuery(input).bind('tap',function(event){
callScan();
});
}
var success = function(status) {
alert('Message: ' + status);
}
var error = function(status) {
alert('Error: ' + status);
}
function callScan(){
scan.read( success, error );
}
</script>
</head>
<body onload="fireItUp()">
<button class="ui-btn ui-corner-all ui-btn-b" onclick="callScan();">Scan</button>
</body>
Upvotes: 0
Views: 414
Reputation: 6029
You cannot use custom plugins on PhoneGap Build unless you submit the plugin to PhoneGap Build and they approve it. By doing this your plugin will be added to the thirdparty section of available plugins. There is currently no way to add a private custom plugin using PhoneGap Build
Upvotes: 2