2015-12-17 59 views
1

我想在Android中執行我的本機代碼,並且我正在獲取無盡的異常。我試圖啓動本機撥號程序並撥打號碼,而不必按撥號程序上的呼叫按鈕。請幫助並提供一個完整的工作代碼,這裏是我有codenameone中的本地接口,

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

本地接口代碼:

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; 
} 
} 
+1

您提供的代碼並未顯示您是如何實現本機界面和獲取的異常的。我們可以幫助您修復代碼並提出可行的建議,而不是爲您編寫代碼。 – Diamond

+1

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; } } –

+1

你有什麼特例?您是否爲Intent,Uri和Activity添加了導入語句?我相信你正在測試Android設備連接到ddms? – Diamond

回答

1

環繞你的本機代碼中:

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

這將有效地將您的代碼移動到大多數Android代碼所期望的Android本機事件分派線程。