Question

When running this

String ussdCode = "*" + "100" + Uri.encode("#");
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));

I expect a normal phone call to be done, but instead of that Skype go to front and make the call for *100# USSD code. I logged out from Skype and it sill brings Skype to front!.
How to force it to use the normal phone call instead of Skype?

Was it helpful?

Solution

Thats because you have Skype as the default application for calls. This is a device configuration. You can change it, but note that if you does, it will actualy change that configation, so skype wont be the default any more in your mobile.

You can clear the default application calling this form your activity

getPackageManager().clearPackagePreferredActivities(PACKAGENAME);

the package name of skype is com.skype.raider, so in your case you call this

getPackageManager().clearPackagePreferredActivities("com.skype.raider");

of course you call it before you call the startActivity

UPDATE

I remembered that if you don't want to reset default configuration, you can try to force one app to handle the intent you are sending to startActivity. But you have a problem, you will have to know the package name of the application, and the activity which should handle it. In some cases that will be easy to find out, but in some other it wont. I've been googling for this information for the default android dialer, and also looked in my device, but i didn't find anything. Anyways, if you can find it, you can use the code below and it will be much better since it doesn't change any setting. Also you can remember it since it could be handy in other situations:

Intent intent = new Intent();
intent.setComponent(new ComponentName("PACKAGE_NAME","PACKAGENAME.ACTIVITY_NAME"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
    startActivity(intent);
}
catch (Exception e)
{
   e.printStackTrace();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top