国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android短信發(fā)送器實現方法

2020-04-11 11:25:54
字體:
來源:轉載
供稿:網友

本文實例講述了Android短信發(fā)送器實現方法。分享給大家供大家參考。具體如下:

這里模擬android短信發(fā)送器的實現

AndroidManifest.xml清單文件:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ljq.sms" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" 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-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.SEND_SMS"/></manifest> 

main.xml布局文件:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"  android:layout_width="fill_parent" android:layout_height="fill_parent"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="115dip"  android:layout_height="wrap_content"   android:text="請輸入手機號"  android:id="@+id/mobilelabel" /> <EditText android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:layout_toRightOf="@id/mobilelabel"   android:text="5556"  android:id="@+id/mobile" /> </RelativeLayout> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content"  android:text="請輸入短信內容" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content"  android:minLines="3" android:text="I am a teacher!" android:id="@+id/content" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content"  android:text="發(fā)送" android:id="@+id/button" /></LinearLayout>

MainActivity類:

package com.ljq.sms;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 mobileText=null; private EditText contentText=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mobileText=(EditText)findViewById(R.id.mobile); contentText=(EditText)findViewById(R.id.content); Button button=(Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener(){  public void onClick(View v) {  String mobile=mobileText.getText().toString();  String content=contentText.getText().toString();  //取得android系統(tǒng)中默認的短信管理器  SmsManager manager=SmsManager.getDefault();  //如果短信內容過長時,則對短信內容進行拆分  ArrayList<String> texts=manager.divideMessage(content);  for(String text:texts){   //第一個參數:對方手機號碼   //第二個參數:短信中心號碼,一般設置為空   //第三個參數:短信內容   //第四個參數:sentIntent判斷短信是否發(fā)送成功,如果你沒有SIM卡,或者網絡中斷,則可以通過這個intent來判斷。   //注意強調的是“發(fā)送”的動作是否成功。那么至于對于對方是否收到,另當別論   //第五個參數:當短信發(fā)送到收件人時,會收到這個deliveryIntent。即強調了“發(fā)送”后的結果   //就是說是在"短信發(fā)送成功"和"對方收到此短信"才會激活sentIntent和deliveryIntent這兩個Intent。這也相當于是延遲執(zhí)行了Intent   manager.sendTextMessage(mobile, null, text, null, null);  }  //Toast.makeText(getApplicationContext(), "發(fā)送成功", Toast.LENGTH_LONG).show();  Toast.makeText(MainActivity.this, "發(fā)送成功", Toast.LENGTH_LONG).show();  } }); }}

運行結果:

希望本文所述對大家的Android程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 汉中市| 崇左市| 泸西县| 昌吉市| 虎林市| 长治县| 蒙山县| 右玉县| 莱阳市| 榆树市| 凤城市| 宣恩县| 西林县| 林州市| 县级市| 团风县| 闽清县| 元江| 连云港市| 新疆| 武穴市| 宁德市| 蒲城县| 天镇县| 墨竹工卡县| 桑日县| 古丈县| 天水市| 建平县| 乌拉特前旗| 蒙山县| 临海市| 通河县| 浠水县| 达州市| 辽阳县| 格尔木市| 灵宝市| 称多县| 平安县| 秀山|