Question

in agreement with the recent post from Android Developers http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html ,I was trying to prepare my app to the new android version, but encountered a problem with the part they suggest to create a dialog to let the user set the app as the default application to handle SMS's :

Android Developers Post

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

}

the code itself in pretty much straightforward, but I'm unable to access to Telephony.Sms.getDefaultSmsPackage because it says that Telephony cannot be resolved, and I can't find any import or declaration that would fix that.

Can anyone please help?

Was it helpful?

Solution

android.provider.Telephony simply doesn't exist yet (as of API 18 - 4.3).

This class will be added in 4.4 (presumably API 19), and that blog post is highlighting the changes that you should make once the new API is released so you aren't surprised when the time comes.

From the end of the post:

To help you make the changes, we'll soon be providing the necessary SDK components for Android 4.4 that allow you to compile and test your changes on Android 4.4.

Don't forget that you should wrap this code in an API version check so you don't run into issues with older versions that don't have this class.

OTHER TIPS

this change will break all the SMS blocking apps. "Note that—beginning with Android 4.4—any attempt by your app to abort the SMS_RECEIVED_ACTION broadcast will be ignored so all apps interested have the chance to receive it."

Do you think there is a way to go around this?!

Maybe at least on Root?

Apparently there is with root access. The latest version Cerberus app claim to be doing this.

Now, if only I knew how they do it :(

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top