有谁知道通过代码阻止传入/传出SMS消息的可靠方法?可以接收实际的SMS消息,但是可以,但是我想阻止接收该SMS的任何通知.同样,不应允许用户发送(或最好键入)SMS消息.那可能吗?
谢谢
解决方法:
您不能阻止传出的短信.
这是我用来阻止传入文本的内容.
SmsReceiver.java
import androID.content.broadcastReceiver;import androID.content.Context;import androID.content.Intent;import androID.os.Bundle;import androID.telephony.SmsMessage;import androID.Widget.Toast;public class broadCastReceiver extends broadcastReceiver {/** Called when the activity is first created. */private static final String ACTION = "androID.provIDer.Telephony.SEND_SMS";public static int MSG_TPE=0;public voID onReceive(Context context, Intent intent) { String MSG_TYPE=intent.getAction(); if(MSG_TYPE.equals("androID.provIDer.Telephony.SMS_RECEIVED")) {// Toast toast = Toast.makeText(context,"SMS Received: "+MSG_TYPE , Toast.LENGTH_LONG);// toast.show(); Bundle bundle = intent.getExtras(); Object messages[] = (Object[]) bundle.get("pdus"); SmsMessage smsMessage[] = new SmsMessage[messages.length]; for (int n = 0; n < messages.length; n++) { smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]); } // show first message Toast toast = Toast.makeText(context,"BLOCKED Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG); toast.show(); abortbroadcast(); for(int i=0;i<8;i++) { System.out.println("Blocking SMS **********************"); } } else if(MSG_TYPE.equals("androID.provIDer.Telephony.SEND_SMS")) { Toast toast = Toast.makeText(context,"SMS SENT: "+MSG_TYPE , Toast.LENGTH_LONG); toast.show(); abortbroadcast(); for(int i=0;i<8;i++) { System.out.println("Blocking SMS **********************"); } } else { Toast toast = Toast.makeText(context,"SIN ELSE: "+MSG_TYPE , Toast.LENGTH_LONG); toast.show(); abortbroadcast(); for(int i=0;i<8;i++) { System.out.println("Blocking SMS **********************"); } }}}
AndroIDManifest.xml
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="APP.PACKAGE.nameHERE"androID:versionCode="1"androID:versionname="1.0" ><uses-sdk androID:minSdkVersion="10" /><supports-screens androID:largeScreens="true" androID:normalScreens="true" androID:smallScreens="true" androID:resizeable="true" androID:anyDensity="true" /><uses-feature androID:name="androID.harDWare.telephony" /><uses-permission androID:name="androID.permission.READ_SMS" /><uses-permission androID:name="androID.permission.WRITE_SMS" /><uses-permission androID:name="androID.permission.SEND_SMS" /><uses-permission androID:name="androID.permission.RECEIVE_SMS" /><uses-permission androID:name="androID.permission.RECEIVE_MMS" /><application androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" > <activity androID:name=".APPACTIVITYHERE" androID:label="@string/app_name" androID:configChanges="orIEntation|keyboardHIDden" > <service androID:name=".MyService" androID:enabled="true"/> <receiver androID:name="SmsReceiver"> <intent-filter androID:priority="2147483647"> <action androID:name="androID.provIDer.Telephony.SMS_SENT"/> </intent-filter> </receiver> <service androID:name=".MyServiceSentReceived" androID:enabled="true"/> <receiver androID:name="SmsReceiver"> <intent-filter androID:priority="2147483645"> <action androID:name="androID.provIDer.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver></application>
从清单中删除的主要内容是服务块,接收器块和权限.
总结以上是内存溢出为你收集整理的在Android上阻止传入/传出的短信全部内容,希望文章能够帮你解决在Android上阻止传入/传出的短信所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)