最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實戰(zhàn)教程第四篇之簡單實現(xiàn)短信發(fā)送器

 更新時間:2016年11月10日 11:54:11   作者:楊道龍  
這篇文章主要為大家詳細(xì)介紹了Android實戰(zhàn)教程第四篇之簡單實現(xiàn)短信發(fā)送器,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android發(fā)短信功能的實現(xiàn)方法,供大家參考,具體內(nèi)容如下

首先配置一個布局:

<LinearLayout 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" 
 android:orientation="vertical" 
 > 
 
 <EditText 
 android:id="@+id/et_phone" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:inputType="phone" 
 android:hint="請輸入對方號碼" 
 /> 
 <EditText 
 android:id="@+id/et_content" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:lines="5" 
 android:hint="請輸入短信內(nèi)容" 
 android:gravity="top" 
 /> 
 <Button 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="發(fā)送" 
 android:onClick="send" 
 /> 
 
</LinearLayout>

 然后在activity中把發(fā)短信的代碼寫出來:

package com.ydl.smssender; 
 
import java.util.ArrayList; 
 
//省略導(dǎo)包 
 
public class MainActivity extends Activity { 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main); 
 } 
 
 
 public void send(View v){ 
 //拿到用戶輸入的號碼和內(nèi)容 
 EditText et_phone = (EditText) findViewById(R.id.et_phone); 
 EditText et_content = (EditText) findViewById(R.id.et_content); 
  
 String phone = et_phone.getText().toString(); 
 String content = et_content.getText().toString(); 
  
 //1.獲取短信管理器 
 SmsManager sm = SmsManager.getDefault(); 
  
 //2.切割短信,把長短信分成若干個小短信 
 ArrayList<String> smss = sm.divideMessage(content);//an ArrayList of strings that, in order, comprise the original message 
  
 //3.for循環(huán)把集合中所有短信全部發(fā)出去 
 for (String string : smss) { 
  
  sm.sendTextMessage(phone, null, string, null, null);//Send a text based SMS. 
 } 
 } 
 
} 

發(fā)短信是需要系統(tǒng)權(quán)限的:

復(fù)制代碼 代碼如下:
<uses-permission android:name="android.permission.SEND_SMS"/>
 

效果:

開了兩個模擬器,實現(xiàn)了發(fā)短信功能。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

香河县| 潢川县| 磐安县| 丹江口市| 汉中市| 武功县| 西丰县| 神池县| 屯门区| 贵德县| 和顺县| 中阳县| 永靖县| 新源县| 屏山县| 济南市| 巩义市| 和顺县| 都匀市| 纳雍县| 开封市| 元江| 迭部县| 揭西县| 九台市| 仁怀市| 卫辉市| 体育| 建始县| 睢宁县| 西充县| 张家港市| 屏东市| 全州县| 鄯善县| 郓城县| 锡林浩特市| 文山县| 肃南| 武平县| 西吉县|