核心代码四部分:

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核心分析(21)----Android应用框架之AndroidApplication
  2. Android之实现手机号码拦截
  3. Android 获取手机号
  4. Android核心基础(二)
  5. Android实现输入手机号时自动添加空格
  6. Android核心基础(七)
  7. Android手机号、串号获取

随机推荐

  1. Android 2.2 API Demos -- Redirection,
  2. Android开发最佳学习路线图
  3. android 动态获取res资源id
  4. Android http 请求
  5. Android DownloadManager的用法
  6. 谈谈 Android 中的各种设备标识符
  7. Android常用Demo及开源项目集锦
  8. Android与J2ME区别之我见(2)
  9. android通过代码控制ListView上下滚动
  10. Android 2.1 与 Android 2.2 共存之道