android 验证短信是否发送成功
2012-12-04 20:40:33 来源:WEB开发网核心提示::name</span><span>=</span><span class="attribute-value">".AutoSendMessageBroadcastReceiver"</span><span cla
:name</span><span>=</span><span class="attribute-value">".AutoSendMessageBroadcastReceiver"</span><span class="tag">></span><span> </span></span></li><li class=""><span> <span class="tag"><</span><span class="tag-name">intent-filter</span><span> </span><span class="attribute">android:priority</span><span>=</span><span class="attribute-value">"1000"</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"><</span><span class="tag-name">action</span><span> </span><span class="attribute">android:name</span><span>=</span><span class="attribute-value">"android.intent.action.SENT_SMS_ACTION"</span><span class="tag">/></span><span> </span></span></li><li class=""><span> <span class="tag"></</span><span class="tag-name">intent-filter</span><span class="tag">></span><span> </span></span></li><li class="alt"><span> <span class="tag"></</span><span class="tag-name">receiver</span><span class="tag">></span><span> </span></span></li><li class=""><span><span class="tag"></</span><span class="tag-name">pre</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span> </span></span></li><li class="alt"><span><span class="tag"><</span><span class="tag-name">pre</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"code"</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"java"</span><span class="tag">></span><span>public class AutoSendMessageBroadcastReceiver extends BroadcastReceiver { </span></span></li><li class=""><span> </span></li><li class="alt"><span> @Override </span></li><li class=""><span> public void onReceive(Context context, Intent intent) { </span></li><li class="alt"><span> // TODO Auto-generated method stub </span></li><li class=""><span> switch (getResultCode()) { </span></li><li class="alt"><span> </span></li><li class=""><span> case -1: </span></li><li class="alt"><span> Toast.makeText(context, "短信发送成功", Toast.LENGTH_SHORT).show(); </span></li><li class=""><span> break; </span></li><li class="alt"><span> </span></li><li class=""><span> case 0: </span></li><li class="alt"><span> Toast.makeText(context, "发送失败", Toast.LENGTH_LONG).show(); </span></li><li class=""><span> break; </span></li><li class="alt"><span> </span></li><li class=""><span> default: </span></li><li class="alt"><span> </span></li><li class=""><span> break; </span></li><li class="alt"><span> } </span></li><li class=""><span> } </span></li><li class="alt"><span> </span></li><li class=""><span>}<span class="tag"></</span><span class="tag-name">pre</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span> </span></span></li><li class="alt"><span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span> </span></span></li><li class=""><span><span class="tag"><</span><span class="tag-name">pre</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">pre</span><span class="tag">></span><span> </span></span></li></ol></div><pre name="code" class="html" style="display: none; "> <div class="dp-highlighter bg_java"><div class="bar"><div class="tools"><b>[java]</b> <a href="#" class="ViewSource" title="view plain" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" class="CopyToClipboard" title="copy" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy</a><a href="#" class="PrintSource" title="print" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" class="About" title="?" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a><div style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 99; "><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="0" height="0" name="ZeroClipboardMovie_3" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&width=0&height=0" wmode="transparent"></div></div></div><ol start="1" class="dp-j"><li class="alt"><span><span>PendingIntent sentIntent = PendingIntent.getBroadcast(getApplicationContext(), </span><span class="number">0</span><span>, </span><span class="keyword">new</span><span> Intent(SENT_SMS_ACTION), </span><span class="number">0</span><span>); </span></span></li><li class=""><span> manager.sendTextMessage(num, <span class="keyword">null</span><span>, content, sentIntent, </span><span class="keyword">null</span><span>);</span><span class="comment">//判断是否发送成功</span><span> </span></span></li></ol></div><pre name="code" class="java" style="display: none; ">PendingIntent sentIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(SENT_SMS_ACTION), 0);
更多精彩
赞助商链接