0
在下面的代碼我試圖有一個文本框和一個按鈕,用戶將輸入文本和按鈕上按我只是發送短信到硬編碼值,但我沒有得到任何異常和但是當我發送短信的應用程序關閉錯誤日誌doest有任何東西,我試圖在真實的設備上不是一個模擬器。有任何機構知道這裏可能是什麼問題Android發送短信
<uses-permission android:name="android.permission.SEND_SMS"/>
try {
EditText et =(EditText) findViewById(R.id.editText1);
final String smstext =et.getText().toString().trim();
sms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (smstext != "" || smstext != null)
{
SmsManager smsmgr=SmsManager.getDefault();
smsmgr.sendTextMessage("+xxxxxxxx", null, smstext , null , null);
}
else
{
Toast.makeText(getApplicationContext(),"Enter Message", Toast.LENGTH_SHORT).show();
}
}
});
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(),"Send SMS error: "+ e, Toast.LENGTH_SHORT).show();
}
main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent">
<EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
<Button android:text="Send SMS" android:id="@+id/sms" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Back" android:id="@+id/back1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
我在做類似的事情! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42