2

i'm developing an application to send and receive SMS. I want to add the option to set my application as default like Hangout of Google:

Do you have an ideas? Thanks a lot.

Community
  • 1
  • 1
sigifredo
  • 152
  • 1
  • 8
  • Please have a look at the link: http://stackoverflow.com/questions/20079047/android-kitkat-4-4-hangouts-cannot-handle-sending-sms-intent http://android-developers.blogspot.in/2013/10/getting-your-sms-apps-ready-for-kitkat.html Hope these links will help you what you want. – sUndeep Feb 10 '15 at 08:58

1 Answers1

8

How to set your app as default messaging app?

Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, YOUR_PACKAGE_NAME);

How to check if your app is default messaging app?

@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean isDefaultSmsApp(Context context) {
    return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context));
}

From the preference activity add OnPreferenceClickListener and add the following code inside it which first check if it is already a default messaging app, then opens a screen where the user can change it else set the current app as the default messaging app. Confirmation screen user will get

 if (isDefaultSmsApp(getActivity())) {
                        startActivityForResult(new Intent(Settings.ACTION_WIRELESS_SETTINGS), 0);
                    } else {
                    final String packageName = getActivity().getPackageName();
                        Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
                        intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName);
                        startActivityForResult(intent, 0);
                    }
Devashish Mamgain
  • 2,077
  • 1
  • 18
  • 39