<p>
</p>
<div class="article_title" style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; font-family: 'Microsoft YaHei'; font-size: 20px; line-height: 30px; text-align: left;">
<h3 style="display: inline; font-size: 20px; font-weight: normal; vertical-align: middle; padding: 0px; margin: 0px;"><span class="link_title"><a style="color: #000000; text-decoration: none;" href="http://blog.csdn.net/jjaze3344/article/details/7259272">Android之BroadcastReceiver讲义并通过广播机制实现短信</a></span></h3>
</div>
<div class="article_manage" style="padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; color: #999999; font-family: Arial; line-height: 24px; text-align: right;">
<span class="link_categories" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; float: left;">分类:?<a style="color: #336699; text-decoration: none;" href="http://blog.csdn.net/jjaze3344/article/category/945121">Android之路</a></span><span class="link_postdate" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px;">2012-02-14 20:33</span>?<span class="link_view" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; background-color: initial; background-position: 0% 50%;" title="阅读次数">315人阅读</span>?<span class="link_comments" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 14px; background-color: initial; background-position: 0% 50%;" title="评论次数"><a style="color: #336699; text-decoration: none;" href="http://blog.csdn.net/jjaze3344/article/details/7259272#comments">评论</a>(0)</span>?<span class="link_collect" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px;"><a style="color: #336699; text-decoration: none;" title="收藏" href="http://blog.csdn.net/jjaze3344/article/details/7259272">收藏</a></span>?<span class="link_report" style="margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 5px;"><a style="color: #336699; text-decoration: none;" title="举报" href="http://blog.csdn.net/jjaze3344/article/details/7259272#report">举报</a></span>
</div>
<div id="article_content" class="article_content" style="margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: Arial; font-size: 14px; line-height: 26px; color: #333333; text-align: left;">
<p>本文来源于雷哥(郭老师)。</p>
<p>?</p>
<h1 style="padding: 0px; margin: 0px;"><span style="font-size: 16px;">BroadcastReceiver</span></h1>
<h2 style="padding: 0px; margin: 0px;"><span style="font-size: 16px;">BroadcastReceiver概述:</span></h2>
<p>?</p>
<p>BroadcastReceiver是接收从sendBroadcast()发出的intent的基类。你可以通过Context.registerReceiver()方法在代码中动态的注册一个BroadcastReceiver的实例,也可以通过再AndroidManifest.xml文件中用<receiver>标签来静态声明。</p>
<p>注意:如果你实在Activity.onResume()方法中注册的一个receiver,那么你必须在Activity.onPause()方法中进行注销。(当一个activity处于暂停状态是不会接收intents的,并且这样做也可以减小系统不必要的开销)。不要在Activity.onSaveInstanceState()方法中注销receiver,因为activity从栈中恢复的时候并不会调用这个方法了。</p>
<p>订阅广播的两种方法:</p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">receiver</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"MySMSListener"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">???<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">???????<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">action</span><span style="background-color: inherit; padding: 0px; margin: 0px;">???</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"android.provider.Telephony.SMS_RECEIVED"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">???<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"></</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"></</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">receiver</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
</ol>
</div>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span style="background-color: inherit; padding: 0px; margin: 0px;">IntentFilter?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">filter</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?IntentFilter("android.provider.Telephony.SMS_RECEIVED");??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">IncomingSMSReceiver?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">receiver</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?IncomingSMSReceiver();??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">registerReceiver(receiver,?filter);??</span></li>
</ol>
</div>
<br><p><strong>可以接收的broadcast主要分为两种类型</strong>:<br>???????<strong>普通的broadcasts(</strong>通过Context.sendBroadcast发送)是完全异步的。这个broadcast的receiver以无序的状态运行,经常是在同一时刻运行。这种做法是十分高效的,但是也意味着receiver不能够利用相互处理的结果或者是调用退出的API来退出(因为不知道哪个receiver先接收到intent)。</p>
<p>???????<strong>有序的broadcasts</strong>(通过Context.sendOrderedBroadcast发送)一次只发送给一个receiver。每一个receiver是有序的处理这个intent的,前面的receiver可以传递结果给下一个receiver,或者任意一个receiver都可以完全的退出,这样intent就不会传递给其他的receivers.receiver的执行顺序可以通过匹配的intent-filter中的android:priority属性来控制;如果有多个receivers处于同一个优先级,那么这几个receivers将会以任意的顺序来执行。</p>
<p>?????? 即使是在广播普通的broadcasts的情况下,系统也有可能在某些情况下转换为一次发送一个broadcast给一个receriver。特别是当receivers需要创建进程时,在同一时刻仅仅一个receiver可以运行,避免系统因为这些新建的进程而过载。</p>
<p>?</p>
<p>注意:</p>
<p>尽管Intent类是用来发送和接受这些broadcasts,这里的Intentbroadcast机制和那些通过Context.startActivity()方法来启动activity的intent是完全独立的。一个BroadcastReceiver是没办法观察和捕获一个用于启动activity的intent的;同样的,当你通过intent来发出broadcast时,你也不可能(通过这个intent)找到或者启动一个activity的。这两种操作是完全不同的:通过一个intent来启动一个activity是一个前台操作,会改变用户当前交互的对象;而通过intent来发出broadcast是一个后台操作,用户经常是察觉不到的。</p>
BroadcastReceiver类(通过一个manifest的<receiver>标签作为一个组件启动)是应用程序全局声明周期重要的一部分。<br><br><p><strong>讨论的主题</strong><br>?? 1、Receiver的生命周期<br>?? 2、权限<br>?? 3、进程的生命周期<br></p>
<p><strong>Receiver的生命周期</strong></p>
<p>一个BroadcastReceiver的对象仅仅在调用onReceiver(COntext,Intent)的时间中有效。一旦你的代码从这个函数中返回,那么系统就认为这个对象应该结束了,不能再被激活。你在onReceive(Context, Intent)中的实现有着非常重要的影响:任何对于异步操作的请求都是不允许的,因为你可能需要从这个函数中返回去处理异步的操作,但是在那种情况下,BroadcastReceiver将不会再被激活,因此系统就会再异步操作之前杀死这个进程。</p>
<p>特别是,你不应该再一个BroadcastReceiver中显示一个对话框或者绑定一个服务。对于前者(显示一个对话框),你应该用NotificationManagerAPI来替代,对于后者(绑定一个服务),你可以使用Context.startService()发送一个命令给那个服务来实现绑定效果。</p>
<p>?</p>
<p><strong>权限</strong></p>
<p>存取的权限可以通过在发送方的Intent或者接收方的Intent中强制指定。</p>
<p>?????? 在发送一个broadcast时强制指定权限,就必须提供一个非空的peemission参数给sendBroadcast(Intent,String)或者是sendOrderedBroadcast(Intent, String,BroadcastReceiver, android.os.Handel, int, String, Bundle)。只有那些拥有这些权限(通过在ANdroidManifest.xml文件中相应的声明<uses-permission>标签)的receiver能够接收这些broadcast。</p>
<p>在接收一个broadcast时强制指定权限,就必须在注册receiver时提供一个非空的permission参数--无论是在调用registerReceiver(BroadcastReceiver, IntentFilter,String, android.os.Handler)或者是通过再AndroidManifest.xml文件中通过<receiver>静态标签来声明。只有那些拥有这些权限(通过在相应的AndroidManifest.xml文件中查询<uses-permission>标签来获知)的发送方将能够给这个receiver发送Intent。</p>
<p>对于安全和权限的详细内容请查看Security and Permission文档。</p>
<p>?</p>
<p><strong>进程的生命周期</strong></p>
<p>一个正在执行BroadcastReceiver(也就是,正在执行onReceive(COntext, Intent)方法)的进程被认为是一个前台的进程,将会一直运行,除非系统处于内存极度低的情况下。</p>
<p>一旦从OnReceive()方法中返回,这个BroadcastReceiver将不会再被激活,此时它的主进程就和任何其他运行于此应用程序中的组件拥有相同的优先级。这一点非常重要,如果进程仅仅只是拥有BroadReceiver(一个普遍的情况是用户从不或者是最近没有和它进行交互),因此一旦它从onReceive()方法中返回时,系统就会认为进程是空的并且主动的杀死它,以便这些资源可以被其他重要的进程利用。</p>
<p>这意味着对于耗时的操作,可以采用将Service和BroadcastReceiver结合使用以确保执行这个操作的进程在整个执行过程中都保持激活状态。</p>
<br><h3 style="padding: 0px; margin: 0px;"><span style="font-size: 18px;">短信器</span></h3>
<div>
<p><span style="font-size: 10px;">服务器(videoweb):</span></p>
<p><span style="font-size: 10px;">l? 修改formbean:VideoForm中增加短信的时间、内容和发送者属性</span></p>
<p><span style="font-size: 10px;">l? VideoManageAction中增加方法getSMS来获取器发送的短消息</span></p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span style="background-color: inherit; padding: 0px; margin: 0px;">public?ActionForward?getSMS(ActionMapping?mapping,?ActionForm?form,??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????HttpServletRequest?request,?HttpServletResponse?response)??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????throws?Exception?{??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????VideoForm?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">formbean</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?(VideoForm)form;??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????System.out.println("发送时间:"+?formbean.getTime());??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????System.out.println("谁给她发的短信:"+?formbean.getSender());??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????System.out.println("内容:"+?formbean.getContent());??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????return?mapping.findForward("result");??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">}??</span></li>
</ol>
</div>
<br><p>客户端SMS_Listener</p>
<p>1、?清单文件中订阅广播</p>
<p>?</p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">receiver</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">".MySMSListener"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??????<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">action</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"android.provider.Telephony.SMS_RECEIVED"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">?<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"></</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"></</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">receiver</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
</ol>
</div>
<br><p>?</p>
<p>添加短信接收权限,访问网络权限</p>
<p align="left">?</p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">uses-permission</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"android.permission.INTERNET"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">uses-permission</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"android.permission.RECEIVE_SMS"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
</ol>
</div>
<br><p>?</p>
<p>2、 客户端MySMSListener.java</p>
<p>功能:收取短信广播,接收并解析短信然后发送至服务器端进行后台打印。</p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span style="background-color: inherit; padding: 0px; margin: 0px;">package?cn.class3g.smslistener;??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">import?java.text.SimpleDateFormat;??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">import?java.util.Date;??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">import?java.util.HashMap;??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">import?java.util.Map;??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">import?cn.class3g.utils.SocketHttpRequester;??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">…??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">public?class?MySMSListener?extends?BroadcastReceiver?{??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????public?void?onReceive(Context?context,?Intent?intent)?{??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????Object[]?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">pdus</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?(Object[])?intent.getExtras().get("pdus");??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????if?(pdus?!=?null?&&?pdus.length?<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">?0)?{??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????SmsMessage[]?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">messages</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?SmsMessage[pdus.length];??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????for?(int?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">i</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">0</span><span style="background-color: inherit; padding: 0px; margin: 0px;">;?i?</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">messages.length</span><span style="background-color: inherit; padding: 0px; margin: 0px;">;?i++)?{??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????byte[]?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">pdu</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?(byte[])?pdus[i];??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????messages[i]?=?SmsMessage.createFromPdu(pdu);??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????}??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????for?(SmsMessage?msg?:?messages)?{??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????String?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">content</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">msg</span><span style="background-color: inherit; padding: 0px; margin: 0px;">.getMessageBody();??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????String?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">sender</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">msg</span><span style="background-color: inherit; padding: 0px; margin: 0px;">.getOriginatingAddress();??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????Date?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">date</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?Date(msg.getTimestampMillis());??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????SimpleDateFormat?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">sdf</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?SimpleDateFormat(??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????????????"yyyy-MM-dd?HH:mm:ss");??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??????????????????</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????String?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">sendTime</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">sdf</span><span style="background-color: inherit; padding: 0px; margin: 0px;">.format(date);??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??????????????????</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????Map<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">String</span><span style="background-color: inherit; padding: 0px; margin: 0px;">,String</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">param</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?HashMap</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">String</span><span style="background-color: inherit; padding: 0px; margin: 0px;">,String</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">();??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??????????????????</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????param.put("method",?"getSMS");??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????param.put("sender",?sender);??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????param.put("content",?content);??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????param.put("time",?sendTime);??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??????????????????</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????String?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">path</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=???</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"http://192.168.1.100:8080/videoweb/video/manage.do"</span><span style="background-color: inherit; padding: 0px; margin: 0px;">;??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????try?{??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????????SocketHttpRequester.post(path,?param,?"UTF-8");??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????}?catch?(Exception?e)?{??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????????Log.e("TAG",e.toString());??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????}??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????}??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????}??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????}??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">}??</span></li>
</ol>
</div>
<br><p><strong>SmsMessage</strong></p>
<p>public static SmsMessage createFromPdu(byte[] pdu)</p>
<p>从原始的PDU(protocol description units)创建一个SmsMessage。这个方法很重要,在我们编写短信接收程序要用到,它从我们接收到的广播意图中获取的字节创建SmsMessage。</p>
<p>?</p>
<p>public String getOriginatingAddress ()<br>以String返回SMS信息的来电地址,或不可用时为null。</p>
<p>?</p>
<p>public String getMessageBody ()<br>以一个String返回消息的主体,如果它存在且是基于文本的。</p>
<p>?</p>
<p><strong>短信管理器 : SmsManager</strong></p>
<p>1). 在 Android 2.0 以前 应该使用android.telephony.gsm.SmsManager</p>
<p>?? 之后应该用 android.telephony.SmsManager;</p>
<p>2). 获取系统默认的短信管理器?</p>
<p>SmsManager smsManager =SmsManager.getDefault();</p>
<p>3). 按照每条短信最大字数来拆分短信</p>
<p>?? List<String>divideContents = smsManager.divideMessage(content);</p>
<p>4).?发送短信</p>
<p>???????smsManager.sendTextMessage(destinationAddress,scAddress, text, sentIntent, deliveryIntent)</p>
<p>?????????????--destinationAddress:目标电话号码</p>
<p>?????????????--scAddress:短信中心号码,测试可以不填</p>
<p>?????????????--text:?短信内容</p>
<p>?????????????--sentIntent:发送?-->中国移动?-->?中国移动发送失败?-->?返回发送成功或失败信号?-->?后续处理???即,这个意图包装了短信发送状态的信息</p>
<p>?????????????--deliveryIntent:?发送?-->中国移动?-->?中国移动发送成功?-->?返回对方是否收到这个信息?-->?后续处理??即:这个意图包装了短信是否被对方收到的状态信息(供应商已经发送成功,但是对方没有收到)。</p>
<p>?</p>
<p>5).?声明短信发送权限</p>
<p>?? ??*AndroidManifest.xml</p>
<p>?? ???<uses-permissionandroid:name="android.permission.SEND_SMS"/></p>
<p>?</p>
<p>1、 进一步添加客户端功能:将监听到的指定的短信进行拦截并且自动进行回复</p>
<p>?</p>
<p>添加短信发送权限:</p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">uses-permission</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"android.permission.SEND_SMS"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
</ol>
</div>
<br><p>MySMSListener的onReceive中添加代码如下</p>
<p>?</p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span style="background-color: inherit; padding: 0px; margin: 0px;">String?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">sendContent</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">sdf</span><span style="background-color: inherit; padding: 0px; margin: 0px;">.format(date)?+?":"?+?sender?+?"--"??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????????????????????+?content;??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??????????????????</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">Log.i("TAG",sendContent);??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">if(sender!=?null?&&?sender.endsWith("5556")){//5556".equals(sender)){??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????SmsManager?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">smsManager</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">SmsManager</span><span style="background-color: inherit; padding: 0px; margin: 0px;">.getDefault();??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????smsManager.sendTextMessage("5556",null,"game?over",null,null);??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????this.abortBroadcast();?//终止广播??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">}??</span></li>
</ol>
</div>
<br><p>?</p>
<p>测试:</p>
<p>启动另一个模拟器,向部署客户端的模拟器发送短信,查看服务器端后台输出,并且观察客户端运行模拟器是否有短信接收。</p>
<p>?</p>
<h2 style="padding: 0px; margin: 0px;">补充:</h2>
<p>?????? 除了短信到来广播Intent ,Android 还有很多广播 Intent ,如:开机启动、电池电量变化、时间已经改变等广播 Intent 。</p>
<p>?</p>
<p>l?接收电池电量变化广播 Intent ,在AndroidManifest.xml 文件中的 <application></p>
<p>节点里订阅此 Intent:</p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">receiver</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">".IncomingSMSReceiver"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">???<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">action</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"android.intent.action.BATTERY_CHANGED"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"></</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"></</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">receiver</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
</ol>
</div>
<p>l?接收开机启动广播 Intent , 在AndroidManifest.xml 文件中的 <application> 节点里</p>
<p>订阅此 Intent:</p>
<br><div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">receiver</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">".IncomingSMSReceiver"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">??<span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">action</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=”android.intent.action.BOOT_COMPLETED”?</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"></</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">intent-filter</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;"><</span><span class="tag-name" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">uses-permission</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?</span><span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">android:name</span><span style="background-color: inherit; padding: 0px; margin: 0px;">=</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">"android.permission.RECEIVE_BOOT_COMPLETED"</span><span class="tag" style="color: #993300; background-color: inherit; font-weight: bold; padding: 0px; margin: 0px;">/></span><span style="background-color: inherit; padding: 0px; margin: 0px;">??</span></span></li>
</ol>
</div>
<p>?</p>
<p>通常一个 BroadcastReceiver 对象的生命周期不超过5 秒 , 所以在BroadcastReceiver里不能做一些比较耗时的操作 , 如果需要完成一项比较耗时的工作 , 可以通过发送 Intent给 Activity 或Service ,由 Activity 或 Service 来完成。</p>
<br><div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span style="background-color: inherit; padding: 0px; margin: 0px;">public?class?IncomingSMSReceiver?extends?BroadcastReceiver?{??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????public?void?onReceive(Context?context,?Intent?intent)?{??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????//?发送?Intent?启动服务,由服务来完成比较耗时的操作??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????Intent?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">service</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?Intent(context,?XxxService.class);??</span></span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????context.startService(service);??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????//?发送?Intent?启动?Activity?,由?Activity?来完成比较耗时的操作??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????Intent?<span class="attribute" style="color: red; background-color: inherit; padding: 0px; margin: 0px;">newIntent</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?=?</span><span class="attribute-value" style="color: blue; background-color: inherit; padding: 0px; margin: 0px;">new</span><span style="background-color: inherit; padding: 0px; margin: 0px;">?Intent(context,?XxxActivity.class);??</span></span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????????context.startActivity(newIntent);??</span></li>
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">????}??</span></li>
<li style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; background-color: #f8f8f8; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;">}??</span></li>
</ol>
</div>
<br>当然 , 实现了 BroadcastReceiver , 有时你可能会觉得不需要它 , 那么你可以将已经注册好的 BroadcastReceiver 进行注销 :<br><div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #e7e5dc; width: 687px; margin-top: 18px !important; margin-right: 0px !important; margin-bottom: 18px !important; margin-left: 0px !important; padding-top: 1px;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding-top: 3px; padding-right: 8px; padding-left: 10px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 9px; line-height: normal; color: silver; background-color: #f8f8f8; padding-bottom: 10px; border-left-width: 3px; border-left-style: solid; border-left-color: #6ce26c;">
<strong>[html]</strong>?<a class="ViewSource" style="" title="view plain" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">view plain</a><a class="CopyToClipboard" style="" title="copy" href="http://blog.csdn.net/jjaze3344/article/details/7259272#">copy</a>
<div style="width: 18px; height: 18px;"><embed quality="best" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="18" height="18" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" align="middle" wmode="transparent"></embed></div>
</div>
</div>
<ol class="dp-xml" style="margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 1px !important; margin-left: 45px !important; background-color: #ffffff; color: #5c5c5c; padding: 0px;">
<li class="alt" style="padding-top: 0px !important; padding-right: 3px !important; padding-bottom: 0px !important; padding-left: 10px !important; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: solid; border-color: initial; border-left-width: 3px; border-left-color: #6ce26c; color: inherit; line-height: 18px; margin: 0px !important;"><span style="color: black; background-color: inherit; padding: 0px; margin: 0px;"><span style="background-color: inherit; padding: 0px; margin: 0px;">unregisterReceiver(?BroadcastReceiver?receiver)?;??</span></span></li>
</ol>
</div>
<br><p>思考:</p>
<p>如何在有序的广播中实现intent的修改,比如修改短信内容。</p>
</div>
</div>