Android has been known to add a lot of security measures in 4.4, in addition to setting SELinux to enforce, in the direction of text messages also increased restrictions.
4.4, a new default SMS mechanism, a detailed description, can refer to my other article, " talk about the impact of the new features in 4.4 on the security class software . " In short, if you want to achieve SMS interception after 4.4, you must become the default SMS, all SMS-related functions are swept, and then do SMS interception. But this approach, compatibility and interoperability work is very huge, SMS, Wapush (various), MMS, single card and so on, equivalent to the requirement of SMS interception software to integrate a very well-equipped Address Book class application features.
So, whether there is a way, can not become the default SMS, but also can be the text message "write" (this let 4.4 suddenly back to liberation ah ....) )? The answer is yes.
XDA Daniel Someone has found a more flattering method, the original can refer to here.
The principle is very simple, mainly using 4.2+ after the addition of the app Ops Rights management function, in the Message tab to find their own app, and access to the appropriate rights management interface, as shown, Finaldemo is a demo of my own test:
Notice that the start of the write Sms/mms is off by default, but we can turn it on.
After opening, we can monitor the text message database change method to achieve SMS interception, I also wrote a simple test code, test success, the code and related configuration also put it
<style= "White-space:pre"> </span >Intent Intent = new Intent (intent.action_main); ComponentName cn = New ComponentName ("Com.android.settings", "com.android.settings.Settings"); Intent.setcomponent (CN); Intent.putextra (": Android:show_fragment", "com.android.settings.applications.AppOpsSummary"); StartActivity (intent);
- Configuration of the Androidmanifest.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android"3 Package= "Com.example.finaldemo"4 Android:versioncode= "1"5 Android:versionname= "1.0" >6 <USES-SDK7 android:minsdkversion= "+" />8 <uses-permissionAndroid:name= "Android.permission.READ_SMS" />9 <uses-permissionAndroid:name= "Android.permission.WRITE_SMS" />Ten <uses-permissionAndroid:name= "Android.permission.SEND_SMS" /> One <uses-permissionAndroid:name= "Android.permission.RECEIVE_SMS" /> A <uses-permissionAndroid:name= "Android.permission.RECEIVE_WAP_PUSH" /> - <uses-permissionAndroid:name= "Android.permission.RECEIVE_MMS" /> - <!--<uses-permission android:name= "Android.permission.SEND_SMS"/> - the <Application - Android:allowbackup= "true" - Android:icon= "@drawable/ic_launcher" - Android:label= "@string/app_name" + Android:theme= "@style/apptheme" > - + <Activity A Android:name= "Com.example.finaldemo.MainActivity" at Android:label= "@string/app_name" > - <Intent-filter> - <ActionAndroid:name= "Android.intent.action.MAIN" /> - <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> - </Intent-filter> - </Activity> in <receiver - Android:name=". Smsreceiver " to android:permission= "Android.permission.BROADCAST_SMS" > + - <Intent-filter> the <ActionAndroid:name= "Android.provider.Telephony.SMS_RECEIVED" /> * </Intent-filter> $ Panax Notoginseng </receiver> - the <ServiceAndroid:name= "Com.example.finaldemo.SmsService" /> + A </Application> the </Manifest>
- Code for SMS Interception
1Mobserver =NewContentobserver (NewHandler ()) {2 3 @Override4 Public voidOnChange (BooleanSelfchange) {5 Super. OnChange (selfchange);6Contentresolver resolver =getcontentresolver ();7cursor cursor = resolver.query (Uri.parse ("Content://sms/inbox"),NewString[] {"_id", "address", "Body"},NULL,NULL, "_id desc");8 Longid =-1;9 Ten if(Cursor.getcount () > 0 &&Cursor.movetofirst ()) { Oneid = Cursor.getlong (0); AString address = cursor.getstring (1); -String BODY = cursor.getstring (2); - theToast.maketext (SMSService. This, String.Format ("Address:%s\n Body:%s", address, body), Toast.length_short). Show (); - } - cursor.close (); - + if(id! =-1) { - intCount = Resolver.delete (Sms.content_uri, "_id=" + ID,NULL); +Toast.maketext (SMSService. This, Count = = 1? "Delete succeeded": "Delete Failed", Toast.length_short). Show (); A } at } - - }; - -Getcontentresolver (). Registercontentobserver (Uri.parse ("content://sms/"),true, Mobserver);
Personal Conclusions
- In 4.4 We can not become the default SMS interception, but because the app ops from 4.3 to 4.4 has been hidden in the state of the card, guess that Google is still in the adjustment, 4.4 after the sub-version will be retained, is completely not guaranteed;
- Write Sms/mms the existence of the permission switch and defaultsms itself is a contradiction, the reason for the Write Sms/mms permission switch, is completely because the app ops appeared in front, and Defaultsms appeared in the post-caused;
- Before 4.4, SMS interception was intercepted by dynamic registration of high-priority broadcastreceiver, which was mainly used for SMS preemption with competing products. And now Contenetobserver is the case of parallel notification, if the filter logic is not fast enough, it is still possible to be a competitor to first remove the text message, resulting in the last text message is the old text message. It is recommended to combine broadcastreceiver and contenetobserver to intercept, broadcastreceiver do content correction and backup data, in case the last message is old, can still carry out the normal interception process;
Reprint to: http://blog.csdn.net/l173864930/article/details/17112227