SMS receive only my android Apps , others will not receive -
i want create android application, received sms , not receive native message apps . receive sms , , native message apps receive . coce:..
smsreceiver.java
public class smsreceiver extends broadcastreceiver{ private final string tag = "mysmsreceive"; final smsmanager sms = smsmanager.getdefault(); @override public void onreceive(context context, intent intent) { notificationmanager mnotificationmanager = (notificationmanager) context.getsystemservice(context.notification_service); bundle extras = intent.getextras(); stringbuilder sb = new stringbuilder(); string strmessage = ""; string strmsgbody = ""; string strmsgsrc = ""; if ( extras != null ) { object[] smsextras = (object[]) extras.get( "pdus" ); ( int = 0; < smsextras.length; i++ ) { smsmessage smsmsg = smsmessage.createfrompdu((byte[])smsextras[i]); strmsgbody = smsmsg.getmessagebody().tostring(); strmsgsrc = smsmsg.getoriginatingaddress(); sb.append(smsmsg.getdisplayoriginatingaddress()); sb.append(smsmsg.getdisplaymessagebody()); strmessage += "sms " + strmsgsrc + " : " + strmsgbody; log.d("abcd", "estimateglass estimateglass::" +strmessage); toast toast = toast.maketext(context, "sendernum: "+ strmessage + ", message: ", toast.length_long); toast.show(); } int icon = r.drawable.inbox; charsequence tickertext = strmsgsrc + ": " + strmsgbody; long when = system.currenttimemillis(); notification notification = new notification(icon, tickertext, when); charsequence contenttitle = "new sms message"; charsequence contenttext = sb.tostring(); intent notificationintent = new intent(); pendingintent contentintent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, contenttitle, contenttext, contentintent); notification.vibrate = new long[] { 100, 250, 100, 500}; notification.flags |= notification.flag_auto_cancel; mnotificationmanager.notify(1, notification); } } }
manifest file :
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sms.testreceiveservies" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="19" /> <uses-permission android:name="android.permission.receive_sms" /> <uses-permission android:name="android.permission.write_sms" /> <uses-permission android:name="android.permission.read_sms" /> <uses-permission android:name="android.permission.send_sms" /> <uses-permission android:name="android.permission.vibrate" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <receiver android:name="com.sms.testreceiveservies.smsreceiver" > <intent-filter> <action android:name="android.provider.telephony.sms_received" /> </intent-filter> </receiver> <service android:name=".servicecommunicator" android:enabled="true" /> </application>
please me
pre kitkat 4.4, can call abortbroadcast() make sure have high priority on receiver. post kitkat cannot that, unless default messaging chosen user.
<intent-filter android:priority="1000"><!-- or max int if -->
Comments
Post a Comment