android4.4.2 SMS Broadcast Change

Source: Internet
Author: User

Recently, Samsung has released Android4.4.2rom update package, android4.4.2 to SMS although the permission to release, but in fact is to strengthen the limit, a mobile phone smart through a set as the default application of the SMS application software to send text messages, otherwise it will not be able to operate the SMS database.

Thought just to change this, carefully observe android4.4.2 MMS Source finished, found on the text message broadcast also made some changes, some manufacturers in order to be compatible will continue to send Android.provider.Telephony.SMS_RECEIVED broadcast, But some manufacturers are not honest, on the android4.4 to send Android.provider.Telephony.SMS_DELIVER broadcast, because he only to bring their own SMS application responsible.

Therefore, if the SMS application needs to be compatible with android4.4.2 and the following versions, it is necessary to receive the two broadcasts, so that they can be guaranteed to be received; but always happy too early, changed a android4.4.2 cell phone, found that began to receive duplicate text messages, the original these so-called honest manufacturers, two broadcasts are issued; , how to deal with it?

Here is one of the most Earth way, is to intercept, get SMS time, determine whether the time with the previous message time is the same, if the same does not do processing, is basically a colleague triggered. Although this method is the quickest, but does not feel the reliable, continues to realize, also must continue to analyze the android4.4.2 source code.

The following provides the judgment android4.4.2 default SMS app code:

/** * Default SMS Detection * @param context App Object * @param mypackagename App Package name * @return */public Static Boolean isdefaultsms (Contex T context,string mypackagename) {boolean isdefault=false;try {int currentapiversion=android.os.build.version.sdk_int ; if (currentapiversion>=android.os.build.version_codes. KITKAT) {String defaultsmsapplication = Telephony.Sms.getDefaultSmsPackage (context); if (defaultsmsapplication! = null && defaultsmsapplication.equals (Mypackagename)) {isdefault=true;}}} catch (Exception e) {//Todo:handle Exception}return IsDefault;} /** * Go to set default SMS app * @param context App Object * @param mypackagename app package name */public static void Startsetdefault (Context cont Ext,string mypackagename) {String Action_change_default = "Android.provider.Telephony.ACTION_CHANGE_DEFAULT"; String extra_package_name = "package"; int currentapiversion=android.os.build.version.sdk_int;if (currentapiversion >=android.os.build.version_codes. KITKAT) {if (!isdefaultsms (Context,mypackagename)) {Intent Intent = newIntent (Action_change_default);  Intent.putextra (Extra_package_name, Context.getpackagename ()); Context.startactivity (intent);}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.