标签:android 短信
xml文件代码部分
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" > <EditText android:id="@+id/Phonenum" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入手机号码" /> <EditText android:id="@+id/duanxin" android:layout_width="match_parent" android:layout_height="200px" android:hint="请输入要发送的短信" android:layout_below="@id/Phonenum" /> <Button android:id="@+id/fasong" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送" android:layout_below="@id/duanxin" android:layout_alignParentRight="true" /> </RelativeLayout>
public class MainActivity extends Activity { private EditText phonenum,duanxin; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); phonenum=(EditText)findViewById(R.id.Phonenum); duanxin=(EditText)findViewById(R.id.duanxin); button=(Button)findViewById(R.id.fasong); ButLis lis=new ButLis(); button.setOnClickListener(lis); } class ButLis implements OnClickListener{ @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub String num=phonenum.getText().toString(); SmsManager sms=SmsManager.getDefault(); sms.sendTextMessage(num, null, duanxin.getText().toString(), null, null); } }).start(); } }
本文出自 “Java大白的战地” 博客,请务必保留此出处http://8023java.blog.51cto.com/10117207/1663709
标签:android 短信
原文地址:http://8023java.blog.51cto.com/10117207/1663709