0
嗨,大家好我是新手編程。下面的代碼可以通過按下按鈕將預定義的SMS定義爲預定義的號碼,但它會帶給消息編輯器屏幕,並要求我點擊發送。我如何直接發送短信,而無需轉到消息編輯器。我發現很少有人問這個問題,其中一個解決方案是使用SMSmanger
,但我不知道如何將SMSmanger
代碼用於我的代碼。如何使用SMS SmsManager
public class SendSMSActivity extends Activity {
Button buttonSend;
Button buttonSend2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonSend = (Button) findViewById(R.id.buttonSend);
buttonSend2 = (Button) findViewById(R.id.buttonSend2);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonSend:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "#abc");
sendIntent.putExtra("address", "9900990");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
break;
case R.id.buttonSend2:
Intent sendIntent1 = new Intent(Intent.ACTION_VIEW);
sendIntent1.putExtra("sms_body", "#def");
sendIntent1.putExtra("address", "9900990");
sendIntent1.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent1);
break;
}
}
};
buttonSend.setOnClickListener(listener);
buttonSend2.setOnClickListener(listener);
}
)
謝謝
你嘗試過谷歌? 「如何以編程方式發送短信Android」。 – Sajmon
[Android在按鈕點擊時自動發送短信]的可能重複(http://stackoverflow.com/questions/10607361/android-send-sms-automatically-on-button-click) –
謝謝。 「Android按鈕點擊自動發送短信」答案幫助了我。 – user3296057