In this blog we will write native plugin for Phonegap on Android hwc container.
Useful link
Building Phonegap native plugin for HWC container - IOS
The javascript class
The javacript file will be the same as previos blog
var SupuserinfoAccess = {
devicename: function(types, success, fail) {
return Cordova.exec(success, fail, "Supuserinfo", "getUserinfo", types);
}
};
The Native Class
Get the source code of Android HWC container application on Eclipse for Android and create a new class name it as Supuserinfo.
Open Supuserinfo class you just created and add the following code. As you can see it extends the Plugin superclass.
package com.sybase.hwc;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import com.sybase.messaging.common.ClientConfig;
import com.sybase.messaging.common.persist.Property;
public class Supuserinfo extends Plugin{
public static final String FILEPATH = "getUserinfo";
@Override
public PluginResult execute(String action, JSONArray data, String callbackId) {
// TODO Auto-generated method stub
if (FILEPATH.equals(action)) {
String supUserName = "";
Property oProp = CustomizationHelper.getInstance().getDefaultConnectionAutoRegistration();
oProp = CustomizationHelper.getInstance().getDefaultConnectionUserName();
supUserName = oProp.Value.toString();
return new PluginResult(PluginResult.Status.OK, supUserName);
}
return null;
}
}
Add your plugin to the Plugin.xml file
On hwc container project go to “res->xml” and open the plugin.xml file
Add following xml code to the bottom of the <plugins> tag. Make sure the package name is same as your project.
<plugin name="Supuserinfo" value="com.sybase.hwc.Supuserinfo"/>
Clean project and build again.
Go to the your Hybrid app project and in custom.js file call our plugin to test.
function customAfterWorkflowLoad() {
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady() {
SupuserinfoAccess.devicename(["x"],onSuccess,onFailure);
}
function onSuccess(name){
alert(name);
}
function onFailure(error){
}
Deploy your project to the modified HWC container application and you will get registered username as below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
10 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |