博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android 短信发送器
阅读量:7012 次
发布时间:2019-06-28

本文共 2215 字,大约阅读时间需要 7 分钟。

hot3.png

android短信发送器源码如下:

程序主文件 MainActiviy.java

package com.example.sms;

import java.util.ArrayList;

import android.os.Bundle; import android.app.Activity; import android.telephony.SmsManager; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;

public class MainActivity extends Activity { private EditText numberText; private EditText contentText; private Button button;

@Overridepublic void onCreate(Bundle savedInstanceState) {	super.onCreate(savedInstanceState);	setContentView(R.layout.activity_main);	numberText = (EditText) this.findViewById(R.id.number);	contentText = (EditText) this.findViewById(R.id.content);	button = (Button) this.findViewById(R.id.button);	button.setOnClickListener(new ButtonClickListener());}private final class ButtonClickListener implements View.OnClickListener {	public void onClick(View arg0) {		String number = numberText.getText().toString();		String content = contentText.getText().toString();		SmsManager manager = SmsManager.getDefault();		ArrayList
texts = manager.divideMessage(content); for (String text : texts) { manager.sendTextMessage(number, null, text, null, null); } Toast.makeText(MainActivity.this, "短信已经发送成功", Toast.LENGTH_LONG).show(); }}@Overridepublic boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true;}

}

此文件是布局管理用与下面文件配套使用string.xml <resources>

短信发送器
Hello world!
Settings
短信发送器
请输入手机号
请输入短信内空
发送短信

</resources>

界面布局文件 activity_mian.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" >

</RelativeLayout>

权限配制文件AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sms" android:versionCode="1" android:versionName="1.0" >

</manifest>

转载于:https://my.oschina.net/dragon2013/blog/87177

你可能感兴趣的文章
Cmake 01
查看>>
There is no result type defined for type 'json' mapped with name 'success'. Did you mean 'json'?
查看>>
Linux vi 编辑器的使用
查看>>
Perl 学习手札之三: General syntax
查看>>
Java设计模式之二 ----- 工厂模式
查看>>
Linux vmstat命令实战详解
查看>>
ORA-22858问题
查看>>
DevExpress中ChartControl柱状图(Bar)用法
查看>>
第十四周总结
查看>>
我的管理/创业类文章
查看>>
大数据第六天
查看>>
Java 多线程学习笔记
查看>>
面向对象与原型4---原型
查看>>
操作系统
查看>>
CDMA.ANYDATA 短信接收注意事项(针对乱码问题)
查看>>
neutron用linux_bridge部署provider网络
查看>>
c语言 函数可变参数列表
查看>>
微软职位内部推荐-SW Engineer II for Cloud Service
查看>>
分布式监控开发 02 整体架构设计
查看>>
shell基础篇(二)-shell变量
查看>>