Prevent native mobile run on emulator

0
Hello everyone,   I want after build native mobile app from Mendix, the apk can't run on emulator like Genymotion or the others. Can mendix handle prevention of running on emulator and just running on real device? Please explain!   Thank you
asked
1 answers
0

Hello Fadil

 

Not sure on how you can prevent the app from running on an emulator, but I know a way to discover if your app is on emulator or not.

 

  • Create a javascript action called JSA_IsEmulator on your project
  • Paste the code below on it
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import "mx-global";
import { Big } from "big.js";
import DeviceInfo from 'react-native-device-info';

// BEGIN EXTRA CODE
// END EXTRA CODE

/**
 * @returns {Promise.<void>}
 */
export async function JSA_IsEmulator() {
	// BEGIN USER CODE
	DeviceInfo.isEmulator().then((isEmulator) => {
		if (isEmulator) {
			console.info("EMULATOR");
			alert("EMULATOR");
		}
		else {
			console.info("NOT EMULATOR");
			alert("NOT EMULATOR");
		}		
	});
	// END USER CODE
}
  • Call this javascript action from a Nanoflow
  • Drag this Nanoflow in your Home_Native page to get an action button
  • Install the package below in your JavaScript action folder
npm install --save react-native-device-info

 

After run your project you get the results below (it is a GIF animation, scroll right to see the emulator/device side by side and the correct emulator/not_emulator identification):

 

131933.gif

 

Maybe you canuse this lib and call the isEmulator method from the onload  event on the AppEvents widget  and block the usage of the app if isEmulator ==  true

answered