on 04-30-2021 6:55 PM
Hi Experts,
My plugin is ready, its now embedded in MDK client , now i am trying to call in my rule but it is not triggering. Below is code from my sample angular app , it works for me in sample app. Can you suggest how i can implement below code in my MDK project?
export class HelloWorldModel extends Observable {
constructor() {
super()
this.registerBroadcastReceiver();
this.barcodes = "Barcodes or Scanners will appear here";
Application.android.on(AndroidApplication.activityResumedEvent, (args: AndroidActivityEventData) => {
// Register broadcast receiver in onResume()
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
this.registerBroadcastReceiver();
});
Application.android.on(AndroidApplication.activityPausedEvent, function (args: AndroidActivityEventData) {
// Unregister broadcast receiver in onPause()
console.log("Event: " + args.eventName + ", Activity: " + args.activity);
ZebraPlugin.unRegisterBroadcastReceiver();
});
}
Hi
I assume your plugin is a NativeScript plugin. Is it part of an MDK Extension?
If it is part of an MDK Extension:
It will have been added to your project as part of the extension inclusion, so just import your plugin as per normal in your rule e.g.
import { HelloWorldModel } from 'your-plugin-name'
export default function TestMyPlugin(context){
let a = new HelloWorldModel(); //Or whatever you'd like to do.
alert(a.getSomeValue());
}
If it is not part of an MDK Extension, then:
"NSPlugins": ["/Users/MyUserName/SampleNSPlugin/HelloWorldModel/src"],
"Externals": ["nativescript-your-plugin-name"],
"NSPlugins": ["nativescript-your-plugin-name"],
"Externals": ["nativescript-your-plugin-name"],
Once you have done that, build your app, just import and use your plugin as below:
import { HelloWorldModel } from 'nativescript-your-plugin-name'
export default function TestMyPlugin(context){
let a = new HelloWorldModel(); //Or whatever you'd like to do.
alert(a.getSomeValue());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ming.kho
I don't have issue adding custom plugin in MDK client , i already did that, my issue is how i can implement above code , i need to extend Observable to subscribe to broadcast events on Activity resume and Activity Pause events.
I have text box for which i need to subscribe scan events using broadcast receiver.
Regards
Manish
Hi Manish
MDK Rule must be a JavaScript function, the HelloWorldModel is a TypeScript/Angular class, that is why it's not getting triggered.
My suggestion would be to move HelloWorldModel to your plugin module and then importing the class for consumption in your MDK rule.
import { HelloWorldModel } from 'nativescript-your-plugin-name'
export default function TestMyPlugin(context){
let a = new HelloWorldModel(); //This will trigger HelloWorldModel's constructor
}
Regards
Ming
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.