核心代码四部分:

1、Layout

2、String值

3、MainActivity

4、给项目添加使用授权

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" ><RelativeLayout     android:layout_width="fill_parent"    android:layout_height="wrap_content"    >    <TextView        android:layout_width="100dp"        android:layout_height="wrap_content"        android:text="@string/number"         android:id="@+id/numberLabel"        />        <EditText         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:id="@+id/number"        android:layout_toRightOf="@id/numberLabel"        android:layout_alignTop="@id/numberLabel"        android:layout_marginLeft="5px"        />    </RelativeLayout>    <TextView         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/content"        />        <EditText         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:minLines="3"        android:id="@+id/content"        />        <Button         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/button"        android:id="@+id/button"        /></LinearLayout>

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello World, SecondSmsActivity!</string>    <string name="app_name">短信发送器</string>    <string name="number">请输入手机号</string>    <string name="content">请输入短信内容</string>    <string name="button">发送短信</string><string name="success">发送成功</string></resources>

package com.dcj;import java.util.ArrayList;import android.app.Activity;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 MainActivity extends Activity {private EditText numberText;    private EditText contentText;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                numberText = (EditText) this.findViewById(R.id.number);        contentText = (EditText) this.findViewById(R.id.content);        Button button = (Button) this.findViewById(R.id.button);        button.setOnClickListener(new ButtonClickListener());    }        private final class ButtonClickListener implements View.OnClickListener {public void onClick(View v) {String number = numberText.getText().toString();String content = contentText.getText().toString();SmsManager manager = SmsManager.getDefault();ArrayList<String> texts = manager.divideMessage(content);for (String text : texts) {manager.sendTextMessage(number, null, text, null, null);}Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_SHORT).show();finish();}        }}

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.dcj"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="8" />    <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:name=".MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application>    <uses-permission android:name="android.permission.SEND_SMS"/></manifest>

更多相关文章

  1. Android(安卓)providers 解析之telephony
  2. android发送post请求出现问题
  3. Android调用系统短信发送界面并预设接收号码、短信内容
  4. Android(安卓)bluetooth介绍(四): a2dp connect流程分析
  5. Android(安卓)开发中的倒计时
  6. Android发送短信方法实例详解
  7. Android(安卓)QQ 分享
  8. android发送json并解析返回json
  9. android 模拟按键

随机推荐

  1. 详解PHP使用OSS上传文件
  2. Java杂谈之重复代码是什么
  3. JavaScript实现下拉菜单的显示隐藏
  4. 华纳负责人yy988680
  5. PHP实现根据数组某个键值大小进行排序的
  6. 解构赋值及其在函数传参中的应用
  7. dataset与classlist的使用案例
  8. textarea高度自适应
  9. 自学WEB前端
  10. px em pt区别