brunesto
brunesto

Reputation: 440

how to add own native service in Gluon app

I would like to add sms and email native services (similar to Dialer service) to a Gluon application. I have seen some information regarding the previous version "gluon charms down", but nothing for the later version "gluon attach" ...

Is it still possible to add my own native services in a gluon app using "gluon attach"? I am using maven with com.gluonhq:client-maven-plugin:0.1.32

Upvotes: 2

Views: 186

Answers (1)

brunesto
brunesto

Reputation: 440

Alright, so the only way I found was to generate my own version of attach, with the additional service. There are 2 steps (in bold) which are unexpected:

A.Make a copy of https://github.com/gluonhq/attach

  1. create a new module 'e.g.mynative' as a copy of an existing one. in the new module rename files and ids accordingly

  2. in settings.gradle add lines:

    include 'mynative' 
    ...
    project(':mynative...
 
  1. In ./util/src/main/native/android/c/util.c,

add the lines:

static jclass jMynativeServiceClass;

...

jclass substrateGetRinkainativeServiceClass() {
  return GETREGISTERCLASS(jMynativeServiceClass, 
     "com/gluonhq/helloandroid/DalvikMynativeService");
}
  1. install
    ./gradlew publishToMavenLocal

B. Make a copy of https://github.com/gluonhq/client-maven-plugin

  1. In ./src/main/java/com/gluonhq/attach/AttachService.java add 'MYNATIVE' enum value
  2. install:
     mvn  clean package install

C. Consume service in your gluon mobile app

update version for client-maven-plugin plugin and attach dependency to the ones used in the steps above i.e. xxx-SNAPSHOT

in com.gluonhq:client-maven-plugin configuration add mynative to attachlist

use as other attach services, e.g

Services.get(MynativeService.class).ifPresent(service -> {
    System.err.println("connected:"+service.connectedProperty().get());
});

Then to run on android:

mvn -o -P android clean  client:build client:package client:install client:run

I have not tried it on IOS

Upvotes: 1

Related Questions