I am following this tutorial on setting my app as the default SMS app, but for some reason, my app does not appear in the list of available options. I have tried to research this as much as possible, but everything points back to that same tutorial, or is outdated. Do I need a <receiver>
as well? Can someone explain what I am doing wrong?
The code:
@Override
protected void onResume()
{
super.onResume();
Log.i("MainAcitvity", "On Resume Called");
// Only do these checks/changes on KitKat+, the "mSetDefaultSmsLayout" has its visibility
// set to "gone" in the xml layout so it won't show at all on earlier Android versions.
final String myPackageName = getPackageName();
if (Utility.hasKitKat())
{
if (Utility.isDefaultSmsApp(this))
{
// This app is the default, remove the "make this app the default" layout and
// enable message sending components.
mSetDefaultSmsLayout.setVisibility(View.GONE);
}
else
{
Log.i("MainActivity", "Not Default App");
// Not the default, show the "make this app the default" layout and disable
// message sending components.
mSetDefaultSmsLayout.setVisibility(View.VISIBLE);
Button button = (Button) findViewById(R.id.set_default_sms_button);
button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
Log.i("MainActivity", "Button Pushed");
//Utility.setDefaultSmsApp(MainActivity.this);
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, myPackageName);
startActivity(intent);
}
});
}
}
}
The manifest:
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</activity>
In order for your app to be eligible to be selected as the default messaging app (as far as the system is concerned), you must list all of the components in the manifest as shown in that blog post, whether those components' classes actually exist or not.
Since the system only inspects an app's manifest to determine if it can act as the default messaging app, not all of those components' classes must exist for your app to show in the default selection list. This is useful for learning and testing, but, obviously, if your app is to act as a user's default messaging client, it should fully implement all of the specified components.
If you do intend to perform any SMS/MMS-related tasks, you will also need the relevant permissions. Though the system apparently doesn't check for these when determining eligible default app candidates, the following permissions are necessary for their corresponding operations:
If you're missing the
SEND_SMS
,READ_SMS
, orWRITE_SMS
permission when you attempt to perform the given action, aSecurityException
will be thrown. However, if you're missing aRECEIVE_*
permission, your app will just not be delivered the pertinent broadcasts, and it might seem as though nothing is happening when testing those functionalities.