Cordova Plugins colliding with hardware backbutton

This is a continuation of my recent thread: https://forum.ionicframework.com/t/android-backbutton-issues/139847/19

But with a more approriate thread. To summarize I have issues with getting the backbutton to listen to what I want I want to do, it’s not hooking at all with (app.component.ts) :

platform.registerBackButtonAction(() => {

})

Works totally fine in a fresh project. So I started adding components one by one and noticed that when I added my custom plugin for gathering wifi, bluetooth, gps data. The backbutton no longer worked. Removed it, still didn’t work. Searched the web, saw some people having issues with some other plugins as well. So the problem is pluginrelated.

Does ayone have any idea how to get around this, adding some java code in the plugins to override the backbutton action or anything? Someone must have had this same issue since there are tons of plugins out there, but I caan’t find an approriate sollution and don’t know how to solve it myself.

I get this in the console. Could this have anything to do with the issue?

Ionic Native: deviceready did not fire within 5000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.

Let’s start with the basics:

What is your ionic info output?
Where and how are you testing? (command, device, device OS, device OS version etc)
What does cordova platform list return?
What does cordova plugin list return?

That means that a console.log inside that function is not logged, the function is never triggered. Correct?

Sorry!
Ionic Info


Ionic:

   ionic (Ionic CLI)  : 4.1.1 (C:\Users\daniel karlsson\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.8

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 1.2.1, (and 10 other plugins)

System:

   NodeJS : v8.11.1 (C:\Program Files\nodejs\node.exe)
   npm    : 6.3.0
   OS     : Windows 10

Testing

ionic cordova run android --device
Android: 7.1.1

Cordova platform list

Installed platforms:
  android 7.0.0
Available platforms:
  browser ~5.0.1
  ios ~4.5.4
  osx ~4.0.1
  windows ~5.0.0
  www ^3.12.0

Cordova plugin list

cordova-plugin-android-permissions 1.0.0 "Permissions"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-combainsdk 0.0.1-dev "CombainSDK"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-ionic-keyboard 2.1.2 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.2.1 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-sqlite-storage 2.3.3 "Cordova sqlite storage plugin"
cordova-plugin-combainsdk 0.0.1-dev "CombainSDK"

Ok, which one of the plugins is the culprit in your opinion?

To rule that out, I would suggest you upgrade that to 7.1.1 - the most recent version.

There is also a newer version 2.x of this plugin available which might be wort trying:

And this is strange, a plugin being listed twice:

Any specific reason?

Yes, that is weird. It’s only listed once in my config file. Hmm, could be that I have the working folder inside the plugins folder, will try and rule that out.

Will try what you said. :slight_smile:

I have no idea which one, I know that the CombainSDK does it, but there’s also an other plugin doing it.

Side effects are your enemy in understanding such problem. I would create a new project with ionic start, implement the back button code and run on the device to confirm it works. Then add the plugin you suspect to be the reason - and only that one. (Maybe even remove the plugins that are added by default to a new project first)

Yes, will absolutely try that. But nevertheless. Since the problem is when adding plugins, how do you fix such problems? I mean, is there any Java code to be implemented in the plugin or something?

I am not 100% sure yet it is really triggered by adding a specific plugin - which is why I’m asking you to jump through those hoops.

If this is actually the reason, we will have to try to find out what is going on. Maybe some broken code is executed in JS or Java that breaks things? No idea (yet).

Absolutely :slight_smile:

Just letting you know, I’m not “not caring” about this thread. Working paralell t´with some other stuff. Will test as soon as I get time.

1 Like

Alright, I’ve been adding all the plugins to a fresh project now. Everyone works except my custom one.

1 Like

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");
    }

}

SOLVED: I was stripping down the plugin. I removed everything inside www/combainsdk.js

Now looks like this. So if anyone is ever trying to build anything on top of the device plugin. Remeber this :smile:

var exec = require('cordova/exec');

function CombainSDK () {
    
}

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', []);
}

module.exports = new CombainSDK();

1 Like