Yes, the issue is my custom plugin. Will link the code. Also the duplicate of that plugin was because that I had the working plugin dir inside the plugins folder, moved it out now.
the plugin is build upon the device plugin.
plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:rim="http://www.blackberry.com/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-combainsdk"
version="0.0.1-dev">
<name>CombainSDK</name>
<description>Cordova Combain SDK Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,combainsdk</keywords>
<repo></repo>
<issue></issue>
<js-module src="www/combainsdk.js" name="combainsdk">
<clobbers target="combainsdk" />
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="CombainSDK" >
<param name="android-package" value="org.apache.cordova.combainsdk.CombainSDK"/>
</feature>
</config-file>
<framework src="lib/plugin.gradle" custom="true" type="gradleReference"/>
<source-file src="src/android/CombainSDK.java" target-dir="src/org/apache/cordova/combainsdk" />
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</config-file>
</platform>
<!-- ios -->
<!--<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="Device">
<param name="ios-package" value="CDVDevice"/>
</feature>
</config-file>
<header-file src="src/ios/CDVDevice.h" />
<source-file src="src/ios/CDVDevice.m" />
</platform>-->
<!-- windows -->
<!--<platform name="windows">
<js-module src="src/windows/DeviceProxy.js" name="DeviceProxy">
<runs />
</js-module>
</platform>-->
<!-- browser -->
<!--<platform name="browser">
<config-file target="config.xml" parent="/*">
<feature name="Device">
<param name="browser-package" value="Device" />
</feature>
</config-file>
<js-module src="src/browser/DeviceProxy.js" name="DeviceProxy">
<runs />
</js-module>
</platform>-->
<!-- osx -->
<!--<platform name="osx">
<config-file target="config.xml" parent="/*">
<feature name="Device">
<param name="ios-package" value="CDVDevice"/>
</feature>
</config-file>
<header-file src="src/osx/CDVDevice.h" />
<source-file src="src/osx/CDVDevice.m" />
</platform>-->
</plugin>
package.json
{
"name": "cordova-plugin-combainsdk",
"version": "0.0.1-dev",
"description": "Cordova Combain SDK Plugin",
"types": "./types/index.d.ts",
"cordova": {
"id": "cordova-plugin-combainsdk",
"platforms": [
"android",
"ios",
"windows",
"browser",
"osx"
]
},
"repository": {
"type": "",
"url": ""
},
"bugs": {
"url": ""
},
"keywords": [
"cordova",
"device",
"ecosystem:cordova",
"cordova-android",
"cordova-ios",
"cordova-windows",
"cordova-browser",
"cordova-osx"
],
"scripts": {
"test": "npm run eslint",
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
},
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"engines": {
"cordovaDependencies": {
"3.0.0": {
"cordova": ">100"
}
}
},
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-semistandard": "^11.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-node": "^5.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1"
}
}
www/combainsdk.js
var argscheck = require('cordova/argscheck');
var channel = require('cordova/channel');
var utils = require('cordova/utils');
var exec = require('cordova/exec');
var cordova = require('cordova');
channel.createSticky('onCordovaInfoReady');
// Tell cordova channel to wait on the CordovaInfoReady event
channel.waitForInitialization('onCordovaInfoReady');
/**
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
* phone, etc.
* @constructor
*/
function CombainSDK () {
this.available = false;
this.platform = null;
this.version = null;
this.uuid = null;
this.cordova = null;
this.model = null;
this.manufacturer = null;
this.isVirtual = null;
this.serial = null;
this.hello = null;
var me = this;
channel.onCordovaReady.subscribe(function () {
me.getInfo(function (info) {
// ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
// TODO: CB-5105 native implementations should not return info.cordova
var buildLabel = cordova.version;
me.available = true;
me.platform = info.platform;
me.version = info.version;
me.uuid = info.uuid;
me.cordova = buildLabel;
me.model = info.model;
me.isVirtual = info.isVirtual;
me.manufacturer = info.manufacturer || 'unknown';
me.serial = info.serial || 'unknown';
channel.onCordovaInfoReady.fire();
}, function (e) {
me.available = false;
utils.alert('[ERROR] Error initializing Cordova: ' + e);
});
});
}
/**
* Get device info
*
* @param {Function} successCallback The function to call when the heading data is available
* @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
*/
CombainSDK.prototype.getInfo = function (successCallback, errorCallback) {
argscheck.checkArgs('fF', 'CombainSDK.getInfo', arguments);
exec(successCallback, errorCallback, 'CombainSDK', 'getDeviceInfo', []);
};
CombainSDK.prototype.boot = function(successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'bootSDK', []);
}
CombainSDK.prototype.requestLocation = function(successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'requestLocation', []);
}
CombainSDK.prototype.getLocation = function(successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'getCurrentLocation', []);
}
CombainSDK.prototype.bootUpdateListener = function(successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'bootUpdateListener', []);
}
CombainSDK.prototype.getListenerData = function(successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'getMetaData', []);
}
CombainSDK.prototype.getCountersData = function(successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'getUpdatedCounters', []);
}
CombainSDK.prototype.resetCounters = function(successCallback, errorCallback){
exec(successCallback, errorCallback, "CombainSDK", 'resetCounters', [])
}
CombainSDK.prototype.setToken = function(userToken,successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'setUserToken', [userToken]);
}
CombainSDK.prototype.checkSlmSessionStartStatus = function(selectedBuildingId,successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'checkSlmStartSessionStatus', [selectedBuildingId]);
}
CombainSDK.prototype.checkSlmSessionStopStatus = function(selectedBuildingId,successCallback, errorCallback){
exec(successCallback, errorCallback, 'CombainSDK', 'checkSlmStopSessionStatus', [selectedBuildingId]);
}
CombainSDK.prototype.shutdown = (successCallback, errorCallback) => {
exec(successCallback, errorCallback, 'CombainSDK', 'shutdown', []);
}
/* function boot(){
//exec(successCallback, errorCallback, 'CombainSDK', 'bootSDK', []);
alert('hello');
} */
module.exports = new CombainSDK();
CombainSDK.java
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.cordova.combainsdk;
import java.util.TimeZone;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
//Import Combain SDK
import com.combain.slamsdk.CPSSDK;
import com.combain.slamsdk.UpdateListener;
import com.combain.slamsdk.LocationAvailability;
import com.combain.slamsdk.LocationCallback;
import com.combain.slamsdk.LocationRequest;
import com.combain.slamsdk.LocationResult;
import com.combain.slamsdk.SDKMetaData;
import com.combain.slamsdk.SLAMSession;
import com.sun.corba.se.spi.orbutil.fsm.Action;
//Import what's needed to get the SDK going
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import jdk.nashorn.internal.runtime.JSONFunctions;
import android.provider.Settings;
public class CombainSDK extends CordovaPlugin {
public static final String TAG = "Device";
private String apiKey = "can not show this ;)";
public static String platform; // Device OS
public static String uuid; // Device UUID
public String provider;
private static final String ANDROID_PLATFORM = "Android";
private static final String AMAZON_PLATFORM = "amazon-fireos";
private static final String AMAZON_DEVICE = "Amazon";
private CPSSDK sdk;
double[] locations = new double[3];
private Object floor;
//UpdateListener variables
public float gpsAccuracy;
public int numberBLE;
public int numberWifis;
public int buildingId;
public int nbrOfScans;
public int nbrOfSubmits;
private SLAMSession currentSLAMSession = null;
private LocationCallback locationCallback;
/**
* Constructor.
*/
public CombainSDK() {
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param cordova The context of the main Activity.
* @param webView The CordovaWebView Cordova is running in.
*/
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
CombainSDK.uuid = getUuid();
handleLocationPermission();
}
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackContext The callback id used when calling back into JavaScript.
* @return True if the action was valid, false if not.
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("getDeviceInfo".equals(action)) {
JSONObject r = new JSONObject();
r.put("uuid", CombainSDK.uuid);
r.put("version", this.getOSVersion());
r.put("platform", this.getPlatform());
r.put("model", this.getModel());
r.put("manufacturer", this.getManufacturer());
r.put("isVirtual", this.isVirtual());
r.put("serial", this.getSerialNumber());
callbackContext.success(r);
}else if("initializeSDK".equals(action)){
JSONObject r = new JSONObject();
r.put("uuid", CombainSDK.uuid);
r.put("version", this.getOSVersion());
r.put("platform", this.getPlatform());
r.put("model", this.getModel());
r.put("manufacturer", this.getManufacturer());
r.put("isVirtual", this.isVirtual());
r.put("serial", this.getSerialNumber());
callbackContext.success(r);
}else if("bootSDK".equals(action)){
this.initializeSDK();
this.handleLocationPermission();
if(this.sdk != null){
callbackContext.success("BOOTED");
}else{
callbackContext.error("NOTBOOTED");
}
return true;
}else if("requestLocation".equals(action)){
this.requestLocation(this.locationCallback = new LocationCallback() {
@Override
public void onLocationAvailability(LocationAvailability locationAvailability) {
super.onLocationAvailability(locationAvailability);
}
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
JSONObject r = new JSONObject();
try{
setLocation(
locationResult.getLocations().get(0).getLatitude(),
locationResult.getLocations().get(0).getLongitude()
);
setFloorData(locationResult.getLocations().get(0).getExtras().get("floor"));
r.put("lat", locations[0]);
r.put("lon", locations[1]);
r.put("floor", floor);
callbackContext.success(r);
}catch(JSONException e){
callbackContext.error(e.getMessage());
}
}
});
}else if("getCurrentLocation".equals(action)){
try{
JSONObject r = new JSONObject();
//Add latitude
if(this.locations[0] != 0){
r.put("lat", this.locations[0]);
}else{
r.put("lat", "nopos");
}
//Add longitude
if(this.locations[1] != 0){
r.put("lon", this.locations[1]);
}else{
r.put("lon", "nopos");
}
//Add floor
r.put("floor", floor);
callbackContext.success(r);
}catch(JSONException e){
callbackContext.error(e.getMessage());
}
}else if("bootUpdateListener".equals(action)){
//First, we boot the updateListener
updateListener();
callbackContext.success("BOOTED");
}else if("getMetaData".equals(action)){
//Now we get the data
try{
JSONObject r = new JSONObject();
r.put("gpsaccuracy", this.gpsAccuracy);
r.put("numberofble", this.numberBLE);
r.put("numberifwifis", this.numberWifis);
callbackContext.success(r);
}catch(JSONException e){
callbackContext.error(e.getMessage());
}
}else if("getUpdatedCounters".equals(action)){
//Now we get the data
try{
JSONObject r = new JSONObject();
r.put("numberOfScans", this.nbrOfScans);
r.put("numberOfSubmits", this.nbrOfSubmits);
callbackContext.success(r);
}catch(JSONException e){
callbackContext.error(e.getMessage());
}
}
else if("setUserToken".equals(action)){
try{
JSONObject jsonObject = args.getJSONObject(0);
System.out.println("token"+jsonObject.getString("token"));
setToken(jsonObject.getString("token"));
callbackContext.success("Token Success");
}catch(JSONException e){
callbackContext.error(e.getMessage());
}
}
else if("checkSlmStartSessionStatus".equals(action)){
//this.buildingId = args.getInt(0); [{"bid":167}]
try{
JSONObject jsonObject = args.getJSONObject(0);
System.out.println("building id"+Integer.parseInt(jsonObject.getString("bid")));
this.buildingId = Integer.parseInt(jsonObject.getString("bid"));
boolean slmStatus = startSLMSession(this.buildingId);
JSONObject r = new JSONObject();
r.put("startSlmSessionStatus", slmStatus);
r.put("nbrOfScans", this.nbrOfScans);
r.put("nbrOfSubmit", this.nbrOfSubmits);
callbackContext.success(r);
}catch(JSONException e){
callbackContext.error(e.getMessage());
}
}else if("checkSlmStopSessionStatus".equals(action)){
try{
JSONObject jsonObject = args.getJSONObject(0);
System.out.println("building id stop "+Integer.parseInt(jsonObject.getString("bid")));
this.buildingId = Integer.parseInt(jsonObject.getString("bid"));
boolean slmStatus = stopSLMSession(this.buildingId);
this.nbrOfScans = 0;
this.nbrOfSubmits = 0;
JSONObject r = new JSONObject();
r.put("stopSlmSessionStatus", slmStatus);
r.put("nbrOfScans", this.nbrOfScans);
r.put("nbrOfSubmit", this.nbrOfSubmits);
callbackContext.success(r);
}catch(JSONException e){
callbackContext.error(e.getMessage());
}
}else if("shutdown".equals(action)){
this.locations[0] = 0;
this.locations[1] = 0;
this.sdk.removeLocationUpdates(this.locationCallback);
callbackContext.success("shutdownsuccess");
}else if("resetCounters".equals(action)){
}
else {
return false;
}
return true;
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
/**
* Get the OS name.
*
* @return
*/
//Boot the SDK
public void updateListener(){
this.sdk.setUpdateListener(new UpdateListener(){
public void onConnectionStatusChanged(boolean isConnectionGood) {
}
public void onCountersUpdated(int nbrOfScans, int nbrOfSubmits){
setUpdatedCounters(nbrOfScans,nbrOfSubmits);
}
@Override
public void onSDKMetaDataUpdated(SDKMetaData metadata) {
//Then it listens for changes and assign this metadata to variables we can poll on later
setMetaData(metadata.getGpsAccuracy(), metadata.getNbrofBLE(), metadata.getNbrofWifis());
}
});
}
//GPS Accuracy, Number of BLE, Number of Wifis
public void setMetaData(float gpa, int nob, int now){
//Assign the new data
this.gpsAccuracy = gpa;
this.numberBLE = nob;
this.numberWifis = now;
}
public void setUpdatedCounters(int nbrOfScans, int nbrOfSubmits){
this.nbrOfScans = nbrOfScans;
this.nbrOfSubmits= nbrOfSubmits;
}
public void setToken(String token){
System.out.println("token ==="+token);
this.sdk.setUserToken(token);
}
public boolean startSLMSession(int buildingId){
if (currentSLAMSession != null) {
this.sdk.stopSLAMSession(currentSLAMSession);
}
currentSLAMSession = new SLAMSession(buildingId);
boolean startStatus = this.sdk.startSLAMSession(currentSLAMSession);
return startStatus;
}
public boolean stopSLMSession(int buildingId){
boolean stopStatus = false;
if (currentSLAMSession != null) {
stopStatus = this.sdk.stopSLAMSession(currentSLAMSession);
}
return stopStatus;
}
public void initializeSDK(){
this.sdk = new CPSSDK(this.cordova.getActivity().getApplicationContext(), this.apiKey);
this.sdk.setRandomizedID(false);
}
public void setLocation(double lat, double lon){
this.locations[0] = lat;
this.locations[1] = lon;
}
public void setFloorData(Object floor){
this.floor = floor;
}
//Request location
public void requestLocation(LocationCallback loc){
this.sdk.requestLocationUpdates(new LocationRequest(), loc, null);
}
public void handleLocationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this.cordova.getActivity(),
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//boolean shouldAsk = shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE);
ActivityCompat.requestPermissions(this.cordova.getActivity(), new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
}
}
public String getPlatform() {
String platform;
if (isAmazonDevice()) {
platform = AMAZON_PLATFORM;
} else {
platform = ANDROID_PLATFORM;
}
return platform;
}
/**
* Get the device's Universally Unique Identifier (UUID).
*
* @return
*/
public String getUuid() {
String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
return uuid;
}
public String getModel() {
String model = android.os.Build.MODEL;
return model;
}
public String getProductName() {
String productname = android.os.Build.PRODUCT;
return productname;
}
public String getManufacturer() {
String manufacturer = android.os.Build.MANUFACTURER;
return manufacturer;
}
public String getSerialNumber() {
String serial = android.os.Build.SERIAL;
return serial;
}
/**
* Get the OS version.
*
* @return
*/
public String getOSVersion() {
String osversion = android.os.Build.VERSION.RELEASE;
return osversion;
}
public String getSDKVersion() {
@SuppressWarnings("deprecation")
String sdkversion = android.os.Build.VERSION.SDK;
return sdkversion;
}
public String getTimeZoneID() {
TimeZone tz = TimeZone.getDefault();
return (tz.getID());
}
/**
* Function to check if the device is manufactured by Amazon
*
* @return
*/
public boolean isAmazonDevice() {
if (android.os.Build.MANUFACTURER.equals(AMAZON_DEVICE)) {
return true;
}
return false;
}
public boolean isVirtual() {
return android.os.Build.FINGERPRINT.contains("generic") ||
android.os.Build.PRODUCT.contains("sdk");
}
}