Nigel Chomba
Nigel Chomba

Reputation: 59

Native interfaces in codenameone,

I am trying to execute my native code in Android and i am getting endless exceptions.I am trying to launch the native dialer and call a number withouth pressing the call button on the dialer.Please help and provide a full working code,here is what i have

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("*151*1*1*0779083353*2*1#"));
Activity activity = new Activity();
activity.startActivity(callIntent);

Native Interface code:

public class NativeAccessImpl { 
    public void load() { 
       final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity(); 
    } 
    public void payEcocash() { 
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("*151*1*1*0779083353*2*1#")); 
        Activity activity = new Activity(); 
        activity.startActivity(callIntent); 
    } 
} 

t.start(); 

public boolean isSupported() { 
    return true; 
} 
}

Upvotes: 1

Views: 146

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

Wrap your native code in:

com.codename1.impl.android.AndroidNativeUtil.getActivity().runOnUiThread(new Runnable() {
   public void run() {
       // your code goes here
   }
} 

This will effectively move your code to the Android native event dispatch thread which most Android code expects.

Upvotes: 1

Related Questions