欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android基礎(chǔ)開發(fā)小案例之短信發(fā)送器

 更新時(shí)間:2016年05月26日 11:37:24   作者:Gxs丶小宇  
這篇文章主要為大家詳細(xì)介紹了Android基礎(chǔ)開發(fā)小案例之短信發(fā)送器的具體實(shí)現(xiàn)代碼,感興趣的小伙伴們可以參考一下

先看看效果圖:

布局文件:
activity_main.xml

<span style="font-family:Comic Sans MS;font-size:14px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:tools="http://schemas.android.com/tools" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:paddingBottom="@dimen/activity_vertical_margin" 
  android:paddingLeft="@dimen/activity_horizontal_margin" 
  android:paddingRight="@dimen/activity_horizontal_margin" 
  android:paddingTop="@dimen/activity_vertical_margin" 
  tools:context=".MainActivity" > 
 
  <TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="17dp" 
    android:text="請輸入手機(jī)號碼:" 
    android:textSize="20dp" /> 
 
  <EditText 
    android:id="@+id/editText1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView1" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="25dp" 
    android:background="@android:drawable/editbox_dropdown_light_frame" 
    android:ems="10" 
    android:inputType="phone" 
    android:singleLine="true" > 
 
    <requestFocus /> 
  </EditText> 
 
  <TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView1" 
    android:layout_below="@+id/editText1" 
    android:layout_marginTop="39dp" 
    android:text="請輸入短信的內(nèi)容:" 
    android:textSize="20dp" /> 
 
  <EditText 
    android:id="@+id/editText2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView2" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="49dp" 
    android:background="@android:drawable/editbox_background" 
    android:ems="10" 
    android:hint="發(fā)送的內(nèi)容..." 
    android:inputType="textMultiLine" 
    android:lines="5" /> 
 
  <Button 
    android:id="@+id/btn_send" 
    android:layout_width="50dp" 
    android:layout_height="30dp" 
    android:layout_below="@+id/editText2" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="30dp" 
    android:background="@drawable/reply_send_button" /> 
 
</RelativeLayout></span> 

Java代碼:

<span style="font-family:Comic Sans MS;font-size:14px;">package com.bzu.gxs; 
 
import java.util.ArrayList; 
 
import android.os.Bundle; 
import android.app.Activity; 
import android.telephony.SmsManager; 
import android.text.TextUtils; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 
 
public class MainActivity extends Activity implements OnClickListener { 
  private EditText et_number; 
  private EditText et_content; 
  private Button btn_send; 
 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    et_number = (EditText) findViewById(R.id.editText1); 
    et_content = (EditText) findViewById(R.id.editText2); 
    btn_send = (Button) findViewById(R.id.btn_send); 
 
    btn_send.setOnClickListener(this); 
  } 
 
  @Override 
  public void onClick(View v) { 
    switch (v.getId()) { 
    case R.id.btn_send: 
      // 獲取手機(jī)號碼 
      String number = et_number.getText().toString().trim(); 
      // 獲取短信內(nèi)容 
      String content = et_content.getText().toString().trim(); 
      // 判斷手機(jī)和短信的內(nèi)容是否為空 
      if (TextUtils.isEmpty(content) || TextUtils.isEmpty(number)) { 
        Toast.makeText(MainActivity.this, "手機(jī)號 或 短信內(nèi)容 為空 ...", 
            Toast.LENGTH_LONG).show(); 
        return; 
      } else { 
        SmsManager smsManger = SmsManager.getDefault(); 
        // 把短信拆分成多個(gè)片段,防止短信內(nèi)容過長,發(fā)送失敗 
        ArrayList<String> contents = smsManger.divideMessage(content); 
        // 遍歷短信內(nèi)容 
        for (String str : contents) { 
          /* 
           * smsManger.sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent) 
           * sendTextMessage方法的 
           * 第一個(gè)參數(shù)是信息的接收者 
           * 第二個(gè)參數(shù)是短信來自于哪里,目前不支持填寫null就可以 
           * 第三個(gè)參數(shù)短信發(fā)送的內(nèi)容 
           * 第四個(gè)參數(shù)是判斷短信是否發(fā)送成功 
           * 第五個(gè)參數(shù)是對面接收到你發(fā)的短信的一個(gè)消息報(bào)告 
           */ 
          smsManger 
              .sendTextMessage(number, null, content, null, null); 
          Toast.makeText(MainActivity.this, "發(fā)送成功...", 
              Toast.LENGTH_LONG).show(); 
        } 
      } 
      break; 
    } 
  } 
} 
</span> 

以上就是Android短信發(fā)送器的實(shí)現(xiàn)代碼,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android嵌套滾動的傳統(tǒng)方法與思路

    Android嵌套滾動的傳統(tǒng)方法與思路

    Android嵌套滾動是在開發(fā)中經(jīng)常遇到的一個(gè)需求,這篇文章主要介紹了Android嵌套滾動的傳統(tǒng)方法與思路的相關(guān)資料,對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Android中使用SDcard讀取文件

    Android中使用SDcard讀取文件

    這篇文章主要介紹了Android中使用SDcard讀取文件的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • Android10自動連接WiFi問題的解決

    Android10自動連接WiFi問題的解決

    這篇文章主要介紹了Android10自動連接WiFi問題的解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Android編程實(shí)現(xiàn)WebView添加進(jìn)度條的方法

    Android編程實(shí)現(xiàn)WebView添加進(jìn)度條的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)WebView添加進(jìn)度條的方法,涉及Android WebView界面及控件功能相關(guān)操作技巧,需要的朋友可以參考下
    2017-02-02
  • Android單一實(shí)例全局可調(diào)用網(wǎng)絡(luò)加載彈窗

    Android單一實(shí)例全局可調(diào)用網(wǎng)絡(luò)加載彈窗

    這篇文章主要為大家詳細(xì)介紹了Android單一實(shí)例全局可調(diào)用網(wǎng)絡(luò)加載彈窗,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Android-Service實(shí)現(xiàn)手機(jī)壁紙自動更換

    Android-Service實(shí)現(xiàn)手機(jī)壁紙自動更換

    這篇文章主要為大家詳細(xì)介紹了Android-Service實(shí)現(xiàn)手機(jī)壁紙自動更換,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android自定義View基礎(chǔ)開發(fā)之圖片加載進(jìn)度條

    Android自定義View基礎(chǔ)開發(fā)之圖片加載進(jìn)度條

    這篇文章主要介紹了Android自定義View基礎(chǔ)開發(fā)之圖片加載進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android Koin2基本使用的那件事兒

    Android Koin2基本使用的那件事兒

    這篇文章主要給大家介紹了關(guān)于Android Koin2基本使用的那件事兒,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • 使用RadioButton+Fragment實(shí)現(xiàn)底部導(dǎo)航欄效果

    使用RadioButton+Fragment實(shí)現(xiàn)底部導(dǎo)航欄效果

    這篇文章主要為大家詳細(xì)介紹了使用RadioButton+Fragment實(shí)現(xiàn)底部導(dǎo)航欄效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Flutter實(shí)現(xiàn)單選,復(fù)選和開關(guān)組件的示例代碼

    Flutter實(shí)現(xiàn)單選,復(fù)選和開關(guān)組件的示例代碼

    在App開發(fā)過程中,選擇交互是非常常見的,今天主要介紹下關(guān)于選擇的三個(gè)組件的使用:開關(guān)、單選和復(fù)選,感興趣的小伙伴可以了解一下
    2022-04-04

最新評論