Call Uno from Android

Dear Sirs,

I’d like to call stripped uno method from separated Android file which included onto project using UXL Procress macros.

My Code.java contains

                @{ActivityRecognitionModule.FireEventImpl(string,int):Call("UNKNOWN",da.getConfidence())};

While the Uno compiler converts it onto C++ invocation !

::g::ActivityRecognitionModule::FireEventImpl()

Also the ExternedBlockHost doesn’t have the reference for those methods.

Any Ideas ?

Best,
Ahmad

The Android file is extends IntentService so i can find a way to do that using ForeignCode inside Uno file

To stop something getting stripped you can use ‘require entity’

Adding this…

[Require("Entity", "Foo.Bar")]

…to a class that doesnt get stripped. Will stop a class from getting stripped, but a method might still be.

This…

[Require("Entity", "Foo.Bar.DoSomething(ObjC.Object)")]

… will stop the DoSomething method from getting stripped (which also means the class will be kept too)

Your second comment seems unrelated though, to add a using you can read about ForeignInclude from here https://docs.fusetools.com/native-interop/foreign-code.html#java

To subclass IntentService you will want to use a java file and include it in your build using this https://docs.fusetools.com/native-interop/foreign-code.html#external-source-files, which you can then call from foreign methods

I hope this helps!

Thanks Chris for your reply,
I’m already required the entity

    [Require("Entity","ActivityRecognitionModule.fireEvent(string,int)")]

About including in project, what the different between UXL Process macro and .unoproj include?

i will try to include using unoproj and back

Sorry but this code

@{ActivityRecognitionModule.FireEventImpl(string,int):Call("IN_VEHICLE",da.getConfidence())};

Still converted to

::g::ActivityRecognitionModule::FireEventImpl("IN_VEHICLE", da.getConfidence());

While the code is Java ! this my runs fine with Obj-C not Android

what should i do ?

file

Hi again

I ran uno build -tandroid and got tonnes of errors like these

/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/foreign/ActivityRecognitionModule.java:38: error: not a statement
        debug_log "Sup!";
        ^
/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/foreign/ActivityRecognitionModule.java:38: error: ';' expected
        debug_log "Sup!";
                 ^
/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/apps/touringtrackpro/DetectedActivitiesIntentService.java:69: error: illegal start of expression
                    ::g::ActivityRecognitionModule::FireEventImpl("IN_VEHICLE", da.getConfidence());
                    ^
/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/apps/touringtrackpro/DetectedActivitiesIntentService.java:69: error: method references are not supported in -source 1.7
                    ::g::ActivityRecognitionModule::FireEventImpl("IN_VEHICLE", da.getConfidence());
                         ^
  (use -source 8 or higher to enable method references)
/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/apps/touringtrackpro/DetectedActivitiesIntentService.java:69: error: not a statement
                    ::g::ActivityRecognitionModule::FireEventImpl("IN_VEHICLE", da.getConfidence());
                      ^
/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/apps/touringtrackpro/DetectedActivitiesIntentService.java:69: error: ';' expected
                    ::g::ActivityRecognitionModule::FireEventImpl("IN_VEHICLE", da.getConfidence());
                                                                 ^
/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/apps/touringtrackpro/DetectedActivitiesIntentService.java:69: error: ';' expected
                    ::g::ActivityRecognitionModule::FireEventImpl("IN_VEHICLE", da.getConfidence());
                                                                                                  ^
/Users/Baggers/Downloads/tour-tracking/build/Android/Debug/app/src/main/java/com/apps/touringtrackpro/DetectedActivitiesIntentService.java:74: error: illegal start of expression
                    ::g::ActivityRecognitionModule::FireEventImpl("ON_BICYCLE", da.getConfidence());
                    ^

::g::ActivityRecognitionModule::FireEventImpl("IN_VEHICLE", da.getConfidence()); this looks like c++, but the file is .java weird

Oh, onHandleIntent is calling back to uno using the macros. That doesnt work for java files unfortunately.

This is mentioned in https://docs.fusetools.com/native-interop/foreign-code.html#external-source-files (but not very clearly)

Processing of Java files is not yet possible, but will be coming soon.

… it hasnt ‘come soon’ :frowning:

The way to call back is to pass in functions https://docs.fusetools.com/native-interop/foreign-code.html#delegates.

There is also a dirty ‘secret’ way, but this is unsupported so if it doesn’t work then sorry but there wont be help for it:

Make an uno method with the attribute [Foreign(Language.Java), ForeignFixedName] for example

static class Foo
{
    [Foreign(Language.Java), ForeignFixedName]
	static void Bar()
	{
		debug_log("HI!");
    }
}

You can then call this method from a java file by with com.foreign.Foo.Bar();

You can see and example of this used here:

However, if you can use the delegates it’s better :slight_smile:

I hope this helps!

Appreciated, I just need the ForeignFixedName Attribute <3.
Best