# Error at android compile time with foreign code

**URL:** <https://forums.fusetools.com/t/error-at-android-compile-time-with-foreign-code/4705>\
**Category:** How-to Discussions\
**Created:** [February 13, 2017, 6:44pm UTC](https://forums.fusetools.com/t/error-at-android-compile-time-with-foreign-code/4705 "2017-02-13T18:44:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![albertolopezdev](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/albertolopezdev/32/407_2.png) [@albertolopezdev](https://forums.fusetools.com/u/albertolopezdev)\
**Post date:** [February 13, 2017, 6:44pm UTC](https://forums.fusetools.com/t/error-at-android-compile-time-with-foreign-code/4705/1 "2017-02-13T18:44:11Z")

</div>

```
using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;
using Uno.UX;

/*using global::Android.android.media;
using global::Android.android.app;
using global::Android.android.provider;
using global::Android.android.provider;
using global::Android.android.content;
using global::Android.java.util;*/

using Uno.Compiler.ExportTargetInterop;

[ForeignInclude(Language.Java, "java.lang.Runnable", "java.lang.Boolean", "android.app.*", "android.content.Intent", "android.content.Context", "java.lang.*", )]
public class Calendar : NativeModule
{
static readonly Calendar _instance;
public Calendar()

{// Make sure we're only initializing the module once
    // Make sure we're only initializing the module once
    if (_instance != null) return;

    _instance = this;
    Resource.SetGlobalKey(_instance, "Calendar");
    AddMember(new NativeFunction("Calendar", (NativeCallback)AddCalendar));
}

object AddCalendar(Context c, object[] args)
{   
    
    AddCalendar(c, args);
    return null;
}

[Foreign(Language.Java)]
static extern(Android) void AddCalendar(Context context, string begin, string end)
@{
        java.util.Calendar cal = java.util.Calendar.getInstance(); 
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", begin);
        intent.putExtra("allDay", true);
        intent.putExtra("rrule", "FREQ=YEARLY");
        intent.putExtra("endTime", end);
        intent.putExtra("title", "LIMITE FECHA DE PAGO");
        context.startActivity(intent);
        debug_log("Hecho");
@}
}    

```

I am trying to compile my .apk and I get this:

 ![file](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/LKVKIAzDo4mg-image-1487011415844.png)

I have been stuck for hours with foreign code. What I want is to add an event to the calendar from JS, passing the start date and end date as parameters.

---

<div class="post-metadata">

**Author:** ![Remi\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/remi_pedersen/32/432_2.png) [@Remi\_Pedersen](https://forums.fusetools.com/u/Remi_Pedersen)\
**Post date:** [February 14, 2017, 9:48am UTC](https://forums.fusetools.com/t/error-at-android-compile-time-with-foreign-code/4705/2 "2017-02-14T09:48:47Z")

</div>

As the error says you don’t have `context` available. When doing foreign code you can get the Activity / Context as described [here](https://www.fusetools.com/docs/native-interop/foreign-code#getting-the-root-activity).

E.g. this should work: `com.fuse.Activity.getRootActivity().startActivity(intent)` 🙂
