How could I add a native code in Ionic 2?

Hello, I would like to create a background service which will not be killed after user has quitted my app for my Android application. However, it seems that is impossible to create such a service with Ionic 2 or Cordova. So I would like to create in native Java.

The problem is: where should I write my native code and how could my native code work with other parts of my application?

Thank you in advanced.

If you want to use native code in your applications you will need to do it through the use of a Cordova plugin - one that already exists or one you write yourself.

There is a plugin already that does what you’re after, and describes how to do it as well: (I haven’t actually used it before though).