Java-Android 之短信发送
file:///F:/workspace3/Android_ver2.5/src/cn/szy/com/MainActivity.java
package cn.szy.com; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { /** Called when the activity is first created. */ private Button button; private EditText edittext,number; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button)this.findViewById(R.id.button); number = (EditText)this.findViewById(R.id.num); edittext = (EditText)this.findViewById(R.id.content); } public void Opentall(View v){ String num = number.getText().toString(); String content = edittext.getText().toString(); SmsManager manager = SmsManager.getDefault(); ArrayList<String> texts = manager.divideMessage(content); for(String text : texts){ manager.sendTextMessage(num, null, text, null, null); } Toast.makeText(MainActivity.this, "发送成功", Toast.LENGTH_LONG).show(); } }
AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。