热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

黑马66期android学习笔记17_短信发送器

一、项目结构二、activity_main.xml代码<LinearLayoutxmlns:android"http:schemas.android.comapkresa

一、项目结构


二、activity_main.xml代码

    xmlns:tools="http://schemas.android.com/tools"
android:layout_
android:layout_

android:orientation="vertical"
>

android:id="@+id/et_phone"
android:layout_
android:layout_
android:hint="请输入号码"
android:inputType="phone"
/>
android:id="@+id/et_content"
android:layout_
android:layout_
android:lines="5"
android:hint="请输入内容"
android:text="oohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohohooohhohohohohohohohohoho"
android:gravity="top"
/>


三、MainActivity.java代码

package com.example.sendnote;

import java.util.ArrayList;

import android.support.v7.app.ActionBarActivity;
import android.telephony.SmsManager;
import android.util.Log;
import android.os.Bundle;

import android.view.View;
import android.widget.EditText;

public class MainActivity extends ActionBarActivity {
private static final String TAG="MainActivity";
private EditText phone;
private EditText content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phOne=(EditText)findViewById(R.id.et_phone);
cOntent=(EditText)findViewById(R.id.et_content);
}

public void send(View v){
String phOneText=phone.getText().toString();
String cOntentText=content.getText().toString();
Log.i(TAG, "发送号码:"+phoneText);
Log.i(TAG, "发送内容:"+contentText);
//直接使用短信api,进行发送
SmsManager sm=SmsManager.getDefault();

//如果短信过长,会导致短信不发送,在这先把短信内容处理为多个短信
ArrayList al=sm.divideMessage(contentText);
for (String string : al) {
sm.sendTextMessage(phoneText, null,string, null, null);
}

}
}

下载地址


推荐阅读
author-avatar
手机用户2602916235
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有