Android4.4 new SMS concepts

Source: Internet
Author: User

Android4.4 introduces a new concept for text messages: default text message application. That is, android users can select a default text message application in the system settings. Only this application can perform basic text message operations on mobile phones. According to google's own explanation, this is because many third-party apps use some hidden API interfaces, which should be reflection calls. Since they are unconventional reflection calls, therefore, these interfaces do not have compatibility, that is, CTS testing, and cannot guarantee stability and reliability. In my opinion, there are too many third-party text message applications on the market, and manufacturers often package their calls, contacts, and text messages. Therefore, there are often multiple text message applications on mobile phones, every application can send and receive text messages, which is a bit confusing. In particular, some applications are not properly handled, resulting in two messages being displayed. . Therefore, this default SMS operation is necessary.
However, since the interface has changed, many things on the APP side need to be changed. How can we restore text messages in the most typical 360 cloud disk-like applications that can restore text messages? Google will give you a suggestion later. Here we will first talk about the changes to the interface.

Google provides the following intents: SMS_DELIVER_ACTION (sms) & WAP_PUSH_DELIVER_ACTION (MMS) to the default text message application. That is to say, only the default text message application can receive the two broadcasts, only applications that can receive the two broadcasts can write data to the short MMS database. That is to say, only the default text message application can store the text message. If you want to receive text messages from other non-default text message applications, you can listen to them:
SMS_RECEIVED_ACTION of course, these applications can only display text messages and cannot be stored in the database. Therefore, the text message applications earlier than 4.4 are taken directly to 4.4. These applications can only view and read the text message, because they do not have the permission to write data to the database. Google provides a control interface: PackageManager. setComponentEnabledSetting () to enable the control. In this way, the application can detect the current android platform and determine whether to disable the broadcast.

In addition, before 4.4, SMS_RECEIVED_ACTION broadcast was an ordered broadcast. Therefore, some applications can discard the broadcast after listening to the broadcast, but after 4.4, the discard action will not take effect, in this way, all text message applications can receive text messages. I personally think this is very reasonable ...... After all, text messages cannot be intercepted by an application.

For non-system text message applications, if you want to send text messages, you can call the SmsManager interface to send text messages after applying for the SEND_SMS permission. The framework writes the text message to the database only after the non-system text message application sends the text message. (The system text message application writes the text message to the database, no more apps will send text messages quietly in the background ......

If an application is not a default text message application, many of its design items are unavailable and the default text message application is very different. Therefore, it is necessary to perform some fault tolerance operations. First, you need to check whether the interface resume is default. You can query: Telephony. Sms. getdefasmsmspackage () to determine whether it is a default text message application. If it is not recommended to send disable text messages, because if the user sends MMS, the system will not help write the data into the database, and the application itself will not be able to write the data into the database, the situation will be very bad ...... Of course, if it is not the default text message application, you can also prompt the user to choose whether to set it. After all, you are willing to click on your application, which is basically intended for use.

Sample:

public class ComposeSmsActivity extends Activity {    @Override    protected void onResume() {        super.onResume();        final String myPackageName = getPackageName();        if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) {            // App is not default.            // Show the "not currently set as the default SMS app" interface            View viewGroup = findViewById(R.id.not_default_app);            viewGroup.setVisibility(View.VISIBLE);            // Set up a button that allows the user to change the default SMS app            Button button = (Button) findViewById(R.id.change_default_app);            button.setOnClickListener(new View.OnClickListener() {                public void onClick(View v) {                    Intent intent =                            new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);                    intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,                             myPackageName);                    startActivity(intent);                }            });        } else {            // App is the default.            // Hide the "not currently set as the default SMS app" interface            View viewGroup = findViewById(R.id.not_default_app);            viewGroup.setVisibility(View.GONE);        }    }}

How can we make your application a qualified default text message application? First, you need to make some declarations in the androidmanifest. xml file to obtain the corresponding permissions:
1. You need to listen to the SMS_DELIVER_ACTION broadcast in the broadcast receiver control. Of course, this receiver must also declare the BROADCAST_SMS permission.
2. You need to listen to the WAP_PUSH_DELIVER_ACTION broadcast in the broadcast receiver control. Of course, the receiver must also declare the BROADCAST_WAP_PUSH permission.
3. on the sms sending interface, you need to listen to ACTION_SENDTO and configure the sms:, smsto:, mms:, and mmsto summaries. If other applications want to send text messages, you can understand this activity.
4. You must have a service that can listen to ACTION_RESPONSE_VIA_MESSAGE. You must also configure sms:, smsto:, mms:, and mmsto, and declare the SEND_RESPOND_VIA_MESSAGE permission. In this way, the user can use your application to send a denial message when calling.

Sample:

 
      ...            
          
              
                               
           
          
          
              
                                   
                
           
          
                      
                                                                  
                   
                   
                   
                   
                   
               
                  
          
              
                                   
                    
                    
                    
                    
                
           
      
 

No write permission. How should backup applications write data to the SMS database? Google provides the following suggestions:
1. First query and record the current default text message application:

String defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(context);

2. Let the user set your application as the default text message application, and how to set the previous sample as the default text message application to restore the text message:

Intent intent = new Intent(context, Sms.Intents.ACTION_CHANGE_DEFAULT);intent.putExtra(Sms.Intents.EXTRA_PACKAGE_NAME, context.getPackageName());startActivity(intent);

3. After the text message is restored, you can restore the default text message application to the text message application recorded in Step 1:

Intent intent = new Intent(context, Sms.Intents.ACTION_CHANGE_DEFAULT);intent.putExtra(Sms.Intents.EXTRA_PACKAGE_NAME, defaultSmsApp);startActivity(intent);

Finally, the author concluded that the text message on June 4.4 Is really strict, and no application can send text messages quietly, and no application can intercept the text message on its own. What should I do if various Butler and security software intercept SMS harassment functions?

Disclaimer: This article is taken from the author's learning about google's official blog and is not directly translated.

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.