Sending USSD code programmatically dials Skype instead of normal phone call - android

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?

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

Related

Skype call via Android intent results in group conversation instead of call

The below code used to work fine:
Uri skypeUri = Uri.parse("skype:<username injected>?call&video=true");
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
this.startActivity(myIntent);
A user would click a button on my app and get re-directed to Skype to place a call with a user:
Recently, this code stopped working. Instead the user still gets redirected to Skype, but when they start the call there's no ringing on their end and the receiver of the 'call' sees this:
Based on Skype docs my code is still correct, but something must have changed. I have ran my app in multiple Android devices and observe the same issue.

Default Browser in Android

On the first boot itself, I want to set the default browser from the three that are already installed on the system. I do not want to give the user the option to select the default browser, I want to set it for him/her.
How do I go about it?
EDIT : The Phone is running ICS.
It is impossible to do. There is no API method which would allow this.
To do it on first boot make one receiver,whenever boot detects on that time call any activity and on activity onCreate method write this
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.browser","com.google.android.browser.BrowserActivity"));
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();
}
This can be done if u develop your own firmware and make it a default app for internet uses.This requires the both firmware and boot permissions from the device to make ur application as the default application.
Any way you can set ur application as always to open the web pages in settings

Intent.ACTION_CALL starts a skype call instead a "normal" phone call

I have the folowing code and im starting it from a dialog fragment button:
uri = "tel:"+ServerDialogCallUs.this.contents.getString("phone_number");
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
Instead of making a normal phone call this code starts a skype call. How can I give the user the option to chose between the normal call and a skype call.
Thanks
actually, i was missing the permission:
<uses-permission android:name="android.permission.CALL_PHONE" />
after adding this permission to the manifest I can chose between a normal and a skype call.
Thanks
Try to call setPackage() method, works fine:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number));
startActitivy(intent);
Had the same issue and tried some answers:
Intent.ACTION_CALL will call, which needs probably the right permission, BUT using Intent.ACTION_DIAL and use an Intent Chooser, I got the right behaviour.
Regarding USSD like "*123*03#" which pops up also as question in this context, where android says, it cannot handle the intent
2.1. Uri.encode("#") is not the solution, it just adds a "23" to the phone numer
2.2. Skype handles the number wrong, it adds the country-code like +001. So Skype does not handle USSDs correctly. But it seems, I have no chance, to exclude this.
So, I did:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.fromParts("tel", "123456", null));
startActivity(Intent.createChooser(intent, ""), REQUEST_CODE));
From my point of view
intent.setPackage("com.android.phone");
is device dependent or at least does not leave "phone" included on my device.
That's because
There is only skype installed as a phone call handler or
You associated skype as default handler for phone calls.
In the latter case, go to settings, apps, skype, and remove that association on the bottom of the app details screen.
Your phone probably has Skype as the default app to handle the Intent.ACTION_CALL
Try the following code:
uri = "tel:"+ServerDialogCallUs.this.contents.getString("phone_number");
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(Intent.createChooser(intent, "Call Using..."));

How do we find the information for launching other app?

I need to allow user to draw/sketch/paint something. There are already many apps(like Skitch, I will use this as an example) that accomplish this task. So I don't want to re-invent the wheel.
In Android, theoretically, we can launch other activity by intent. This is sort of like "pipe" in Unix.
The problem is, I don't know how to get the information for launching Skitch.
To integrate Skitch in my app, I need to know the Action it supports, the returning intent (if any) when it finishes.
I installed Skitch, photoshop, and lots of other touch drawing apps in my device, but this code doesn't work :
Uri data = Uri.fromFile(file);
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(data);
i.setType("image/*");
startActivityForResult(i, ACTIVITY_DRAW);
I can launch Skitch from my app in the following way: but obviously I can't get any returned result this way(code from here).
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.evernote.skitch");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
My question: Is there a standard way to find information for launching a third party app?
Is this site the only way to share/get such information?
Or if you have any suggestions for my problem, please help me.
Thank you!
As you might already know how to call another application Activity from your app ..this way Mentioned Here.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if(list.size() > 0)
{
Log.i("Log", "Have application" + list.size());
startActivity(intent);
}
else
{
Log.i("Log", "None application");
}
All your require is Mainly Two Things to call any Activity
1) Package Name of that Activity
2) Activity Class Name
These two informations only can be available if they are opensource or made free to use .. like Zxing,Google Maps Application.
There is another way to start an application activity like,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + numberField.getText())); // set the Uri
startActivity(intent);
For this way to use need to know the correct Action for the Activity you want to call and the Correct parameter to pass with.
And again,These information only can be available if they are opensource or made free to use .. like Facebook and Gmail apps to share and post messages.
So If you are searching for anything like which can tell you what you will need to pass to call any specific comercial apps in your device, you wont find it directly.
It's an old question but perhaps it could help somebody to know that Sony's AppXplore application (free) shows the package and name of the activities of every app installed on your device, so you can eventually use them to do explicit Intents.

Programmatically enter secret code like *#*#4636#*#* on Android

On many Android devices you can get into a secret settings menu from Phone app by typing in
*#*#4636#*#*
http://technology-headlines.com/2010/09/17/4636-android-secret-codes/
There are also some other codes.
Is it also possible to open this stuff programmatically?
I've tried this:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
But it just tries to initiate a phone call and of course fails, hangs up and closes the Phone app.
EDIT: The phone *#*#4636#*#* gets saved to my Contact list as "Unknown" but the call just fails. In fact, the secret code only works when you type manually on buttons in Phone app without pressing Call in the end. Is it probably just a hidden feature of Phone app which has nothing to do with calling?
If so, one could open the Phone app programmatically and simulate typing on the buttons.
According to this post
Programmatically press a button in another appplication's activity
this should NOT be possible because if any app on non-rooted phone could just start other apps and press something there, it could take over control of the whole device and do bad things.
Here are some more details but I guess the post is a bit old and even if it worked it may have been changed in current Android versions:
http://mylifewithandroid.blogspot.de/2009/01/generating-keypresses-programmatically.html
So, no easier way to enter secret code?
Is it also possible to open this stuff programmatically?
Yes:
Intent in = new Intent(Intent.ACTION_MAIN);
in.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(in);
You just need to watch logcat output to learn what this magic combination actually opens:
I/ActivityManager(31362): START {act=android.intent.action.MAIN
flg=0x10000000 cmp=com.android.settings/.TestingSettings} from pid
4257
Secret codes exist and work independent of the dialer application. The dialer application just provides a handy interface for these codes. It recognizes the special string and then calls a special intent to invoke the action. You shouldn't use the dialer to call these dialogs. Instead you can call the secret codes directly yourself like the dialer does internally:
Invoking built in secret codes:
What the dialer really does when you enter the code is extracting the number between *#*# and #*#* and then broadcasting the following intent:
sendBroadcast(new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_secret_code://4636")));
Register your own secret codes (if you like):
You can even register your own secret code actions using:
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="4636" />
Source: http://android.amberfog.com/?p=422
Edit: Fixed a bug in the original code (see comment)
try this
String ussdCode = "*" +Uri.encode ("#")+"*"+Uri.encode ("#")+ "4636" + Uri.encode ("#")+"*"+Uri.encode ("#")+"*";
startActivity (new Intent ("android.intent.action.CALL", Uri.parse ("tel:" + ussdCode)));
finally you must encode '#' using Uri.encode()
ACTION_DIAL sends the user to the dialer with the given code (it does not call). So that would be :
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
It would appear that codes are to be dialed, rather than to be called
looking for this
Intent intent = new Intent("android.intent.action.MAIN");
intent.setClassName("com.android.settings", "com.android.settings.Settings$TestingSettingsActivity");
startActivity(intent);
There are different activities for different phone, we can jump to the activity through typing in ##4636##.
And use
adb shell dumsys activity activities
to find the realActivity package and name.
e.g: Xiaomi 8
Intent intent = new Intent("android.intent.action.MAIN");
intent.setClassName("com.android.settings", "com.android.settings.Settings$TestingSettingsActivity");
startActivity(intent);

Categories

Resources