Block incoming/outgoing SMS on Android -
does know reliable way block incoming/outgoing sms messages through code? it's ok if actual sms messages being received, block notifications of sms being received. also, user shouldn't allowed send (or prefferably type) sms message. possible?
thanks
you can't block outgoing text messages.
here's use blocking incoming texts.
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 activity 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]; (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>
the main thing take away manifest service block, receiver block, , permissions.
Comments
Post a Comment