Skip to Content

Calling the plugin functions in MDK

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


Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on 5 days ago

    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:

    • You must fist include your plugin via the NSPlugin array in the MDKProject.json
    • If your plugin is locally created (i.e. you have not published it publicly to NativeScript Plugin repo), then you need to provide full path to your plugin. e.g.
    "NSPlugins": ["/Users/MyUserName/SampleNSPlugin/HelloWorldModel/src"],
    "Externals": ["nativescript-your-plugin-name"],
    • If your plugin has been published and available in NativeScript Plugins repo, then you just need to provide the plugin name e.g.
    "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());
    }
    Add a comment
    10|10000 characters needed characters exceeded

    • 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