android发送短信
来源:互联网 发布:海岛奇兵胖子升级数据 编辑:程序博客网 时间:2024/06/05 16:53
发送短信
首先建立一个android的项目,打开Layout下的main.xml文件,拖控件,得到的效果是
然后编辑activity下的.java文件,代码如下
package com.csdn.activity;
import java.util.List;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
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 SmsPhoneActivity extendsActivity {
/** Called when the activity is first created. */
privateButton Btn;
privateEditText editphone,editsms;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Btn= (Button)findViewById(R.id.smsBtn);
editphone=(EditText) findViewById(R.id.callphone);
editsms=(EditText) findViewById(R.id.editsms);
Btn.setOnClickListener(new View.OnClickListener() {
@Override
publicvoid onClick(View v) {
Stringphone=editphone.getText().toString();
Stringsms=editsms.getText().toString();
SmsManagersmsManager=SmsManager.getDefault();
PendingIntentpendingIntent=PendingIntent.getBroadcast(SmsPhoneActivity.this, 0, newIntent(), 0);
if(sms.length()>70){
List<String>texts=smsManager.divideMessage(sms);
for(Stringstr:texts){
smsManager.sendTextMessage(phone,null, str, pendingIntent, null);
}
}else{
smsManager.sendTextMessage(phone,null, sms, pendingIntent, null);
}
Toast.makeText(SmsPhoneActivity.this,"发送成功",Toast.LENGTH_LONG).show();
}
});
}
}
Activity动作写完之后,就是授权,,打开anroidMainfest.xml文件进入建立用户界面如下
授权之后运行项目
出现如下界面
当输入号码输入好短信的信息后,点击发送短信,5554界面如下
5556的界面如下
打开信息;
- android 中发送短信
- android中发送短信
- android发送短信
- Android 发送短信
- Android自动发送短信
- Android发送短信
- android 发送短信sms
- android 发送短信
- android发送短信
- Android短信发送器
- android 之短信发送
- Android自动发送短信
- android短信发送
- Android发送短信
- android 发送短信问题
- android 短信发送程序
- Android发送短信
- Android短信发送程序
- 基于角色的权限设计
- C语言实现所有格式文件复制
- 基于Video4Linux 的USB 摄像头图像采集实现
- Linux的cpufreq(动态变频)技术
- 从今天开始,我决定每天发表些自己的学习见解
- android发送短信
- 工作总结_20120716
- iozone测试
- vim+ctags+cscope阅读源代码
- LAMP网站架构方案分析
- 一个整数数组,长度为n,将其分为m份,使各份的和相等,求m的最大值
- TOEFL词汇:我用句子记
- Android照相机俩种常见的使用方式(一)
- 简单的把矩阵分解成一个正交矩阵和一个对角线全为1的上三角矩阵