android制作简单的短信发送器
来源:互联网 发布:九章算法班视频 编辑:程序博客网 时间:2024/04/29 11:46
Android中制作简单的短信发送器的方法
首先现在布局文件中进行布局
下图是我做的一个简单的布局
其代码为
<LinearLayout 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:orientation=”vertical”
Android:context=”.MainActivity” >
<TextView
Android:layout_width=”match_parent”
Android:layout_height=”warp_parenr”
Android:text=”请输入号码”>
<EditText
Android:id=”@+id/et1”
Android:layout_width=”match_parent”
Android:layout_height=”wrap_parent”
Android:ems=”10”
Android:inputType=”phone”>
<TextView
Android:layout_width=”match_parent”
Android:layout_height=”warp_parent”
Android:text=”请输入短信内容”
<EditText
Android:id=”@+id/et2”
Android:layout_width=”match_parent”
Android:layout_hr=eight=”warp_parent”
Android:inputType=”textMultiLine”
Android:lins=”6”>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="发送短信" />
</LinearLayout>
之后在MainActivity.java中编辑代码
class MainActivity extends Activity{
private EditText et1,et2;
protexted void OnCreate(Bundle savedInstanceState){
super.OnCreate(saveInstanceState);
setContentView(R.layout.activity_main);
et1 =(EditText)findViewById(R.id.et1);
et2 =(EditText)findViewById(R.id.et2);
Button button1 = (button)findViewById(R.id.button1);
Button1.setOnClickListener(new OnClick());
}
class OnCllck implements OnClickListener{
public void OnClick(View w){
String phone = tv1.getText().toString().trim(); //去掉字符串两边的空格
String textMultiLine = tv2.getText().toString();
if(“”.equals(phone)){ //如果号码为空
Toast.makeText(MianActivity.this,”号码不能为空”,0).show();
}
ifelse(“”.equals(textMultiLine)){ //如果字符串为空
Toast.makeText(MianActivity.this,”内容不能为空”,0).show();
}
else{
SmsManager smsManager = SmsManager.getDefault(); //获取对象
smsManager.sandTextManager(phone,null, textMultiLine, null, null);
}
}
}
}
最后添加权限
<uses-permission android:name="android.permission.SEND_SMS"/>
- android制作简单的短信发送器
- Android学习笔记---08_短信发送器的制作
- Android之制作短信发送器
- 制作短信发送器
- 3.android最简单的短信发送器
- Android入门之简单短信发送器
- 短信发送器的简单实现
- Android 简单发送短信实例
- Android简单短信发送示例
- android的短信发送
- Android android下的短信发送器
- Android短信发送器
- android 短信发送器
- android短信发送器
- Android短信发送器
- android短信发送器
- android 短信发送器
- Android短信发送器
- 在华为实习的日子
- 开始博客之旅
- Hibernate-----@OneToMany VS @ManyToOne
- Java中的static使用
- 你不能错过的Android性能测试
- android制作简单的短信发送器
- Hibernate-----@ManyToMany
- Move Zeroes
- Hibernate-----@OneToOne
- 三、类,对象和接口
- Android混淆心得
- JAVA mini 记事本
- apache ab压力测试报错
- 面试的记录