Android Build fail with Foreign Code

I created a uno class with foreign code to call phone. I know that Phone.call(PHONE) method can call but it cannot be chosen SIM in dual SIM handsets. so I made my own Phone call class as follow. My problem is I cannot build app for android. I have no idea where is wrong. Please Help me.

    using Uno;
    using Uno.Collections;
    using Fuse;
    using Fuse.Scripting;
    using Uno.Compiler.ExportTargetInterop;
    using Android.android.app;



    public class InstantCaller : NativeModule
    {
        public InstantCaller()
        {

        AddMember(new NativeFunction("call",
        (NativeCallback)call));
    }
string phNumber;
object call(Context c, object[] args)
{
    //debug_log(args[0].ToString());
    phNumber=args[0] as string;
    debug_log("phone to be called ");
    debug_log(phNumber);
    if(defined(Android)){
       UpdateManager.PostAction(callAndroid);
    }
    else if(defined(IOS)){
        UpdateManager.PostAction(callIOS);
    }
    return null;
}

[Foreign(Language.Java)]
public extern(Android) void callAndroid()
@{
    var ctx = Android.android.app.Activity.GetAppActivity();
    Android.java.lang.String a_ph = phNumber;
    android.content.Intent intent = new android.content.Intent(android.content.Intent.ACTION_CALL, android.net.Uri.parse("tel:"+ android.net.Uri.encode(a_ph)));
    ctx.startActivity(intent);
@}

[Foreign(Language.ObjC)]
public extern(iOS) void callIOS()
@{
   // not implemented yet
@}
}

Hi!

It would be quicker to help if you can provide the error messages you are getting.

Yes I found that phNumber cannot be accessed from foreign scope file

That’s right, you need to pass in all variables you need as arguments

I’ve read Foreign code tutorials, But I don’t understand what you say. Please let me know how to pass in all variables to foreign code.

Hi kyawlay,

Sorry for the confusion, fields can be accessed by using the following

public class NativeTest
{
    public NativeTest()
    {
        DoFieldStuff();
    }

    // static fields
    static int _someField0;
    static Java.Object _someField1;

    // instance fields
    int _someField2;
    Java.Object _someField3;
    Java.Object _someProperty { get; set; }

    [Foreign(Language.Java)]
    public extern(android) void DoFieldStuff()
    @{
        debug_log("--------\nbunch of field accessing\n\n");
        debug_log(@{_someField0});
        debug_log(@{_someField0:Get()});

        debug_log(@{_someField1});
        debug_log(@{_someField1:Get()});

        debug_log(@{NativeTest:Of(_this)._someField2});
        debug_log(@{NativeTest:Of(_this)._someField2:Get()});

        debug_log(@{NativeTest:Of(_this)._someField3});
        debug_log(@{NativeTest:Of(_this)._someField3:Get()});

        debug_log(@{NativeTest:Of(_this)._someProperty:Get()});
        debug_log("---------");
    @}
}

Of course it may just be easier to pass them as arguments like this:

public class NativeTest
{
    public NativeTest()
    {
        DoFieldStuff(_someField0, _someField1);
        DoFieldStuff(_someField2, _someField3);
    }

    // static fields
    static int _someField0;
    static Java.Object _someField1;

    // instance fields
    int _someField2;
    Java.Object _someField3;

    [Foreign(Language.Java)]
    public extern(android) void DoFieldStuff(int a, Java.Object b)
    @{
        debug_log("--------");
        debug_log(a);
        debug_log(b);
        debug_log("---------");
    @}
}

Thank you very much for detail explanation