日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android短信發(fā)送功能實(shí)現(xiàn)技巧分享

編程人員可以對Android手機(jī)操作系統(tǒng)進(jìn)行一些更改來滿足用戶的需求。不過要想對其進(jìn)行修改,首先需要了解其源碼的編寫方式。在這里我們先來看看Android短信功能的具體實(shí)現(xiàn),來體驗(yàn)一下相關(guān)編寫方式。

1: Android短信發(fā)送可以在模擬器中進(jìn)行模擬出來。 

如現(xiàn)在啟動(dòng)一模擬器id 號為5554,運(yùn)行cmd 
telnet localhost 5554

輸入help 可以看到很多用于模擬器中的功能命令

 
 
 
  1. gsm call 134343434   
  2. // 便是呼叫當(dāng)前模擬器命令   
  3. sms send 15555218135 Hello,this is a Message   
  4. // 是向當(dāng)前的模擬器發(fā)送短信息  

2: 相關(guān)類: 

 
 
 
  1. Android.telephony.gsm.SmsManager   
  2. Android.telephony.gsm.SmsMessage   
  3. Android.app.PendingIntent   
  4. Android.widget.Toast  

3:Android短信發(fā)送實(shí)現(xiàn)代碼(節(jié)選) 

 
 
 
  1. String msg ="hello";   
  2. string number = "1234565678";   
  3. SmsManager sms = SmsManager.getDefault();   
  4. PendingIntent pi = PendingIntent.
    getBroadcast(Sms.this,0,new Intent(),0);   
  5. sms.sendTextMessage(number,null,msg,pi,null);   
  6. Toast.makeText(Sms.this,"send success",
    Toast.LENGHT_LONG).show();  

4:Android短信發(fā)送代碼解釋 

上述發(fā)送短信的代碼很簡單,但是其中的幾個(gè)類函數(shù)并不好理解: #t#

Toast.makeText 就是展示一個(gè)提示信息,這個(gè)比較容易理解;

PendingIntent 就是一個(gè)Intent 的描述,我們可以把這個(gè)描述交給別的程序,別的程序

根據(jù)這個(gè)描述在后面的別的時(shí)間做你安排做的事情,By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other 
application was yourself,就相當(dāng)于你的代表了。本例中別的程序就是發(fā)送短信的程序,短信發(fā)送成功后要把intent 廣播出去 。

函數(shù)sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)

前三個(gè)參數(shù)按照文檔比較容易理解,PendingIntent sentIntent 當(dāng)短信發(fā)出時(shí),成功的話sendIntent會(huì)把其內(nèi)部的描述的intent廣播出去,否則產(chǎn)生錯(cuò)誤代碼并通過Android.app.PendingIntent.OnFinished進(jìn)行回調(diào),這個(gè)參數(shù)***不為空,否則會(huì)存在資源浪費(fèi)的潛在問題;

deliveryIntent 是當(dāng)消息已經(jīng)傳遞給收信人后所進(jìn)行的PendingIntent 廣播。

查看PendingIntent 類可以看到許多的Send函數(shù),就是PendingIntent在進(jìn)行被賦予的相關(guān)的操作。

Android短信發(fā)送的相關(guān)實(shí)現(xiàn)方法就為大家介紹到這里。


標(biāo)題名稱:Android短信發(fā)送功能實(shí)現(xiàn)技巧分享
路徑分享:http://m.5511xx.com/article/cdjpgpc.html