Andorid 4.4 (KITKAT) has made changes to many aspects of the system, in the current project, the text has a direct impact. Let's take a look at the following document description:
Advice for SMS backup & Restore Apps
Because the ability to write to the Smsprovider are restricted to the app the user selects as the default SMS app, Anyexist ing app designed purely to backup and restore SMS messages would currentlybe unable to restore SMS messages on Android 4.4. An app, backs up andrestores SMS messages must also is set as the default SMS app so that it canwrite messages in the SMS Provider.
Therefore, we need to do a corresponding adaptation of 4.4
public class Smsreceiver extends Broadcastreceiver {@Override public void onreceive (context context, Intent Intent) { Bundle extras = Intent.getextras (); if (extras = = null) {return; } object[] Smsextras = (object[]) extras.get ("PDUs"); if (Smsextras = = NULL | | smsextras.length = = 0) {return; } contentresolver Contentresolver = Context.getcontentresolver (); for (Object Smsextra:smsextras) {try {byte[] smsbytes = (byte[]) Smsextra; Smsmessage smsmessage = SMSMESSAGE.CREATEFROMPDU (smsbytes); Contentvalues values = new Contentvalues (); Values.put (Sms.address, smsmessage.getoriginatingaddress ()); Values.put ( Sms.body, Smsmessage.getmessagebody ()); Values.put (Sms.date, Smsmessage.gettimestampmillis ()); Values.put (Sms.READ , 0); Values.put (Sms.type, Sms.message_type_inbox); Contentresolver.insert (Uri.parse ("content://sms"), values);} catch (Exception e) {e.printstacktrace ();}} }}
public class Mmsreceiver extends Broadcastreceiver {@Overridepublic void OnReceive (context context, Intent Intent) {//TOD O}}
MMS does not use much in daily life, does not do the corresponding treatment
public class Composesmsactivity extends Activity {}
public class Headlesssmssendservice extends Intentservice {public headlesssmssendservice () {Super (headlesssmssends Ervice.class.getName ()); Setintentredelivery (TRUE); } @Override protected void Onhandleintent (Intent Intent) {String action = intent.getaction (); if (! TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals (ACTION)) {return; } Bundle Extras = Intent.getextras (); if (extras = = null) {return; } String message = Extras.getstring (Intent.extra_text); Uri Intenturi = Intent.getdata (); String recipients = getrecipients (Intenturi); if (textutils.isempty (recipients)) {return; } if (Textutils.isempty (message)) {return; } string[] Destinations = textutils.split (recipients, ";"); Sendandstoretextmessage (Getcontentresolver (), destinations, message); }/** * Get quick response recipients from URI */PRivate string getrecipients (Uri uri) {string base = Uri.getschemespecificpart (); int pos = Base.indexof ('? '); return (pos = =-1)? Base:base.substring (0, POS); }/** * Send text message to recipients and store the message to SMS Content Provider * * @param contentres Olver Contentresolver * @param destinations recipients of message * @param message message */private void Sendandstoretextmessage (Contentresolver contentresolver, string[] destinations, String message) {Smsmanager SmsMan Ager = Smsmanager.getdefault (); for (String destination:destinations) {try{smsmanager.sendtextmessage (destination, NULL, message, NU ll, NULL); Contentvalues values = new Contentvalues (); Values.put (sms.address, destination); Values.put (sms.body, message); Values.put (Sms.date, System.currenttimemillis ()); Values.put (sms.read, 0); values.put (Sms.type, sms.message_type_sent); COntentresolver.insert (Uri.parse ("content://sms"), values); }catch (Exception e) {e.printstacktrace (); } } }}
Androidmenifest.xml:
<!--Activity that allows the user to send new SMS/MMS messages---<activity android:name= "Packagename.a Ctivity. Composesmsactivity "> <intent-filter> <action android:name=" Android.intent.action.SE ND "/> <action android:name=" Android.intent.action.SENDTO "/> <c Ategory android:name= "Android.intent.category.DEFAULT"/> <category android:name= "android.intent.cate Gory. browsable "/> <data android:scheme=" sms "/> <data android:scheme=" Smsto "/> <data android:scheme= "MMS"/> <data android:scheme= "Mmsto"/> </int Ent-filter> </activity> <!--broadcastreceiver that listens for incoming SMS messages-- > <receiver android:name= "packageName.receiver.SmsReceiver" android:permission= "Android.permis Sion. BroadcAst_sms "> <intent-filter> <action android:name=" Android.provider.Telephony.SMS_DELIV ER "/> </intent-filter> </receiver> <!--Broadcastreceiver that listens for Inc Oming MMS messages-<receiver android:name= "PackageName.receiver.MmsReceiver" Android:permissio n= "Android.permission.BROADCAST_WAP_PUSH" > <intent-filter> <action android:name= "and Roid.provider.Telephony.WAP_PUSH_DELIVER "/> <data android:mimetype=" Application/vnd.wap.mms-message " /> </intent-filter> </receiver> <!--Service that delivers messages fr Om the phone "quick response"-<service android:name= "PackageName.service.HeadlessSmsSendService" android:permission= "Android.permission.SEND_RESPOND_VIA_MESSAGE" android:exported= "true" > <intent-filter> <action android:name= "Android.intent.action.RESPOND_VIA_MESSAGE"/> <category Android:name= "Android.intent.category.DEFAULT"/> <data android:scheme= "sms"/> < ;d ata android:scheme= "Smsto"/> <data android:scheme= "mms"/> <data android:sche Me= "Mmsto"/> </intent-filter> </service>
Another: <manifest/> Inside Don't forget add android:label= "@string/app_name"
For English documents, please visit: http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html