# Call Uno from Android

**URL:** <https://forums.fusetools.com/t/call-uno-from-android/4612>\
**Category:** How-to Discussions\
**Created:** [April 12, 2018, 10:00am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612 "2018-04-12T10:00:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Diab](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/ahmed_diab/32/692_2.png) [@Ahmed\_Diab](https://forums.fusetools.com/u/Ahmed_Diab)\
**Post date:** [April 12, 2018, 10:00am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/1 "2018-04-12T10:00:24Z")

</div>

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

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

```

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

```auto
::g::ActivityRecognitionModule::FireEventImpl()

```

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

Any Ideas ?

Best,  
Ahmad

---

<div class="post-metadata">

**Author:** ![Ahmed\_Diab](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/ahmed_diab/32/692_2.png) [@Ahmed\_Diab](https://forums.fusetools.com/u/Ahmed_Diab)\
**Post date:** [April 12, 2018, 10:01am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/2 "2018-04-12T10:01:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Baggers](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/baggers/32/665_2.png) [@Baggers](https://forums.fusetools.com/u/Baggers)\
**Post date:** [April 12, 2018, 11:34am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/3 "2018-04-12T11:34:13Z")

</div>

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

Adding this…

```auto
[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…

```auto
[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](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](https://docs.fusetools.com/native-interop/foreign-code.html#external-source-files), which you can then call from foreign methods

I hope this helps!

---

<div class="post-metadata">

**Author:** ![Ahmed\_Diab](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/ahmed_diab/32/692_2.png) [@Ahmed\_Diab](https://forums.fusetools.com/u/Ahmed_Diab)\
**Post date:** [April 12, 2018, 11:42am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/4 "2018-04-12T11:42:34Z")

</div>

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

```auto
    [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

---

<div class="post-metadata">

**Author:** ![Ahmed\_Diab](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/ahmed_diab/32/692_2.png) [@Ahmed\_Diab](https://forums.fusetools.com/u/Ahmed_Diab)\
**Post date:** [April 12, 2018, 11:48am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/5 "2018-04-12T11:48:09Z")

</div>

Sorry but this code

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

```

Still converted to

```auto
::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 ?

---

<div class="post-metadata">

**Author:** ![Ahmed\_Diab](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/ahmed_diab/32/692_2.png) [@Ahmed\_Diab](https://forums.fusetools.com/u/Ahmed_Diab)\
**Post date:** [April 12, 2018, 11:56am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/6 "2018-04-12T11:56:37Z")

</div>

![file](https://canada1.discourse-cdn.com/flex035/uploads/fusetools1/original/1X/7d70beb4e96c187b48d4f3a2e7a94b7fc21cade9.png)

---

<div class="post-metadata">

**Author:** ![Baggers](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/baggers/32/665_2.png) [@Baggers](https://forums.fusetools.com/u/Baggers)\
**Post date:** [April 27, 2018, 9:30am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/7 "2018-04-27T09:30:19Z")

</div>

Hi again

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

```auto
/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](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’ ☹

The way to call back is to pass in functions [https://docs.fusetools.com/native-interop/foreign-code.html#delegates](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

```auto
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:

- [the uno side](https://github.com/fuse-compound/Fuse.Firebase/blob/ede5fa58fdc989e35ee5d2e201c00253093393b9/src/Firebase.Notifications.Android/Android/Impl.uno#L65)
- [the call from java](https://github.com/fuse-compound/Fuse.Firebase/blob/ede5fa58fdc989e35ee5d2e201c00253093393b9/src/Firebase.Notifications.Android/Android/PushNotificationIDService.java)

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

I hope this helps!

---

<div class="post-metadata">

**Author:** ![Ahmed\_Diab](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/ahmed_diab/32/692_2.png) [@Ahmed\_Diab](https://forums.fusetools.com/u/Ahmed_Diab)\
**Post date:** [April 27, 2018, 9:36am UTC](https://forums.fusetools.com/t/call-uno-from-android/4612/8 "2018-04-27T09:36:28Z")

</div>

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