Android system broadcast SMS
来源:互联网 发布:乐乎lofter4.9.0 编辑:程序博客网 时间:2024/06/18 09:35
1.Activity
package com.alan.broadcast1;import android.content.IntentFilter;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;/** * Created by CanxinQiu on 2016/9/1. * Description: Broadcast lesson, register receiver in Java code * SMS_RECEIVED example * */public class MainActivity extends AppCompatActivity { private MyReceiver myReceiver; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); IntentFilter filter = new IntentFilter(); filter.addAction("android.provider.Telephony.SMS_RECEIVED"); myReceiver = new MyReceiver(); registerReceiver(myReceiver,filter); } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(myReceiver); }}
2.BroadcastReceiver
/* * Copyright (c) 2016 All Rights Reserved By FFCS */package com.alan.broadcast1;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.telephony.SmsMessage;import android.util.Log;/** * Created by CanxinQiu on 2016/8/31. * Description: Broadcast lesson, is listen system,include register receiver in Manifest * and in BroadcastReceiver to receive the action,than do something. * SMS_RECEIVED example */public class MyReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Log.i("Broadcast","Received SMS_Message"); //get sms data,send to broadcast receiver Bundle bundle = intent.getExtras(); //pdus is the data's key,so that to get data,that is array form Object object [] = (Object[])bundle.get("pdus"); //only include 140 byte,if sms's data may too long , // that we shall create a array which length suitable SmsMessage [] messages = new SmsMessage[object.length]; for (int i = 0; i < messages.length; i++) { messages[i] = SmsMessage.createFromPdu((byte [])object [i]); //get message content Log.i("SMS body",messages[i].getMessageBody()); } //get sender's number,number is at the beginning of message array Log.i("SMS_TELPHONE NUMBER",messages[0].getOriginatingAddress()); }}
1 0
- Android system broadcast SMS
- Android system broadcast SMS
- 【Android】利用广播Broadcast接收SMS短信
- Android SMS abort system default notify
- android开发之不死Service(Broadcast+system/app)
- Android Service 不被杀掉方法(broadcast+system/app)
- Android 保证Service不被杀掉(broadcast+system/app)
- android Sms
- android sms
- android:sms
- android sms
- Android SMS
- android SMS
- Broadcast system调用
- Android BroadCast
- Android Broadcast
- android broadcast
- android broadcast
- Angular JS路由插件ui.router源码解析
- javascript时间戳相关函数
- 我们可以很容易操作的SEO减法
- 本地线程储存
- 广告栏使用ViewPager无限滑动的问题
- Android system broadcast SMS
- Android将bitmap保存到自定义路径
- 国内CA机构沃通错误颁发GitHub域名SSL证书
- switc—case 语句
- IK Analyzer 类图关系
- MySQL数据的主从复制、半同步复制和主主复制详解
- C#读取XML文件,反序列化为指定对象
- spring mvc拦截器和<mvc:annotation-driven />的详解
- iOS 广告轮播图的实现与封装