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);}}}