diff --git a/Mohem/CordovaHMSPlugin/CordovaHMSLocationPlugin/src/android/CordovaHMSLocationPlugin.java b/Mohem/CordovaHMSPlugin/CordovaHMSLocationPlugin/src/android/CordovaHMSLocationPlugin.java index caef5fd0..4b094ad5 100644 --- a/Mohem/CordovaHMSPlugin/CordovaHMSLocationPlugin/src/android/CordovaHMSLocationPlugin.java +++ b/Mohem/CordovaHMSPlugin/CordovaHMSLocationPlugin/src/android/CordovaHMSLocationPlugin.java @@ -27,6 +27,7 @@ import org.json.JSONException; /** * */ + // https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References-V1/data-types-0000001056511617-V1#section2512153819346 public class CordovaHMSLocationPlugin extends CordovaPlugin { private static final String TAG = CordovaHMSLocationPlugin.class.getSimpleName(); @@ -62,7 +63,7 @@ public class CordovaHMSLocationPlugin extends CordovaPlugin { private void returnLocation(Location location) { if (mCallbackContext != null) { Log.d(TAG, "returnLocation"); - String message = location.getLatitude() + "," + location.getLongitude(); + String message = location.getLatitude() + "," + location.getLongitude() + "," + location.isFromMockProvider(); PluginResult result = new PluginResult(PluginResult.Status.OK, message); result.setKeepCallback(true); mCallbackContext.sendPluginResult(result); diff --git a/Mohem/config.xml b/Mohem/config.xml index f1bfd97d..5ad4f1b7 100644 --- a/Mohem/config.xml +++ b/Mohem/config.xml @@ -106,7 +106,7 @@ - + diff --git a/Mohem/package.json b/Mohem/package.json index 94d82c02..21093409 100644 --- a/Mohem/package.json +++ b/Mohem/package.json @@ -136,6 +136,8 @@ "@types/jasminewd2": "~2.0.3", "@types/node": "~10.12.0", "codelyzer": "~4.5.0", + "com.huawei.cordovahmsgmscheckplugin": "file:CordovaHMSPlugin/CordovaHMSGMSCheckPlugin", + "com.huawei.cordovahmslocationplugin": "file:CordovaHMSPlugin/CordovaHMSLocationPlugin", "cordova-ios": "^6.2.0", "cordova-plugin-wifiwizard2": "^3.1.1", "es6-promise-plugin": "^4.1.0", @@ -201,6 +203,8 @@ }, "phonegap-nfc": {}, "wifiwizard2": {}, + "com.huawei.cordovahmsgmscheckplugin": {}, + "com.huawei.cordovahmslocationplugin": {}, "cordova-plugin-x-socialsharing": {}, "cordova-plugin-firebasex": { "FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true", diff --git a/Mohem/src/app/hmg-common/hmg_utils.ts b/Mohem/src/app/hmg-common/hmg_utils.ts index f8a7737b..d2e72588 100644 --- a/Mohem/src/app/hmg-common/hmg_utils.ts +++ b/Mohem/src/app/hmg-common/hmg_utils.ts @@ -41,7 +41,7 @@ export class HMGUtils { async isHuaweiDevice(): Promise { - var result = await new Promise((resolve, reject) => { + var result: any = await new Promise((resolve, reject) => { cordova.plugins.CordovaHMSGMSCheckPlugin.isHmsAvailable( "index.js", (_res) => { @@ -50,12 +50,12 @@ export class HMGUtils { }, (_err) => { reject({ "status": false, "error": JSON.stringify(_err) }); - alert("Error checking device HMS/GMS") + alert("Error checking device HMS/GMS") // add your popup } ); }); - return (result == true); + return result; } private getHMSLocation(callBack: Function) { @@ -68,10 +68,12 @@ export class HMGUtils { console.log("Huawei Location Success: [Stop Getting]"); cordova.plugins.CordovaHMSLocationPlugin.removeLocation("", (_res) => { }, (_err) => { }); var location = _res.split(',') + console.log(location); if (location.length == 2) { var lat = Number(_res.split(',')[0]); var long = Number(_res.split(',')[1]); - callBack({"latitude":lat, "longitude":long, "isfake":false}) + var mock = Boolean(_res.split(',')[2]); + callBack({"latitude":lat, "longitude":long, "isfake":mock}) } else { alert("Invalid Huawei location from plugin."); } diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.html b/Mohem/src/app/home/attendance-options/attendance-options.component.html index 145721f3..6c847e84 100644 --- a/Mohem/src/app/home/attendance-options/attendance-options.component.html +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.html @@ -19,6 +19,7 @@ +

umarrrrrrrrrrrrrrrr {{check}}

diff --git a/Mohem/src/app/home/attendance-options/attendance-options.component.ts b/Mohem/src/app/home/attendance-options/attendance-options.component.ts index 8de622b0..df7428bd 100644 --- a/Mohem/src/app/home/attendance-options/attendance-options.component.ts +++ b/Mohem/src/app/home/attendance-options/attendance-options.component.ts @@ -19,7 +19,9 @@ import { DevicePermissionsService } from 'src/app/hmg-common/services/device-per import { Geolocation } from '@ionic-native/geolocation/ngx'; import { BackgroundGeolocation } from '@ionic-native/background-geolocation/ngx'; import { FirebaseX } from '@ionic-native/firebase-x/ngx'; +import { HMGUtils } from 'src/app/hmg-common/hmg_utils'; +declare var cordova: any; @Component({ selector: "app-attendance-options", @@ -47,6 +49,7 @@ export class AttendanceOptionsComponent implements OnInit { public firebasex: FirebaseX public isDocumentAvailable = false; public document: any; + public check: any; constructor( @@ -63,7 +66,8 @@ export class AttendanceOptionsComponent implements OnInit { private openNativeSettings: OpenNativeSettings, private devicePermissionsService:DevicePermissionsService, private geolocation: Geolocation, - public backgroundGeolocation: BackgroundGeolocation + public backgroundGeolocation: BackgroundGeolocation, + public hmgUtils: HMGUtils ) {} ngOnInit() { @@ -76,6 +80,18 @@ export class AttendanceOptionsComponent implements OnInit { this.priviligeList = AuthenticationService.servicePrivilage; this.setServicesPrivilage(); this.checkNFCStatus("one"); + this.test(); + } + + async test () { + const test = await this.hmgUtils.isHuaweiDevice(); + if (test) { + this.check = 'this device is huawei device :' + test; + console.log('this device is huawei device :' + test); + } else { + this.check = 'this device is not huawei device :' + test; + console.log('this device is non-huawei device :' + test); + } } public checkFirebaseDocument() {