Android 傳送簡訊 sms

來源:互聯網
上載者:User

 Android 傳送簡訊 sms

 

layout布局檔案main.xml

<?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" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/mobile" />    <EditText        android:id="@+id/mobile"        android:layout_width="fill_parent"        android:layout_height="wrap_content" />    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/content" />    <EditText        android:id="@+id/content"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:minLines="3" />    <Button        android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/button" /></LinearLayout>

 

 

strings.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello SMSActivity!</string>    <string name="app_name">簡訊發送器</string>    <string name="mobile">請輸入手機號</string>    <string name="content">請輸入簡訊內容</string>    <string name="button">傳送簡訊</string>    <string name="success">傳送簡訊成功</string></resources>

 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.cloud.android.sms"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="7" />    <!-- 程式添加傳送簡訊許可權 --><uses-permission android:name="android.permission.SEND_SMS"/>    <application        android:icon="@drawable/agree_logo"        android:label="@string/app_name" >        <activity            android:label="@string/app_name"            android:name=".Sms_cloudActivity" >            <intent-filter >                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

 

Sms_cloudActivity.java

package com.cloud.android.sms;    import java.util.List;    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;  /** * 簡訊發送器(手動) * @author 李海雲 * @email CloudComputing.cc@gmail.com * @date 2012-02-26 00:06:22 */public class Sms_cloudActivity extends Activity {      @Override      public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);                    Button button = (Button)this.findViewById(R.id.button);          button.setOnClickListener(new View.OnClickListener() {                            @Override              public void onClick(View v) {                  //擷取手機號和內容                   EditText mobileText = (EditText)findViewById(R.id.mobile);                  EditText contentText = (EditText)findViewById(R.id.content);                  String mobile = mobileText.getText().toString();                  String content = contentText.getText().toString();                                                  //傳送簡訊                   SmsManager smsManager = SmsManager.getDefault();                  List<String> texts = smsManager.divideMessage(content);//如果超過漢字,自動拆分簡訊                   for(String text : texts){                      smsManager.sendTextMessage(mobile, null, text, null, null);                  }                                    //使用多士通知                   Toast.makeText(Sms_cloudActivity.this, R.string.success, Toast.LENGTH_LONG).show();              }          });      }  }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.