Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 簡訊發送與廣播接收監聽實作

編輯:關於 Android 程式設計

發送簡訊

Android 可透過 SmsManager 發送簡訊。若內容過長,可先呼叫 divideMessage 將訊息拆成多段,再逐一送出。實作時要在 AndroidManifest.xml 加入 SEND_SMS 權限,並依新版 Android 的執行期權限機制向使用者請求授權。

監聽簡訊

若要接收簡訊,可建立 BroadcastReceiver,攔截 android.provider.Telephony.SMS_RECEIVED 廣播。接收到 Intent 後,從 pdus 欄位解析 SmsMessage,即可取得發送者、內容與時間。這類功能常用於驗證碼自動填入或通知提醒。

權限與隱私

簡訊屬於敏感資料,除了 RECEIVE_SMS,通常也需要 READ_SMS 等權限。由於各家系統與應用商店對隱私權限審查嚴格,正式上線前應確認功能是否為使用者清楚可見,並避免濫用背景監聽。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved