I have this code, that works fine in Android 4.4 and previous:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
Now, in Android 5.0 Lollipop this code doesn't work, and shows this exception:
Fatal Exception: android.content.ActivityNotFoundException
No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxx pkg=com.android.phone }
In the documentation, this Intent doesn't appear deprecated:
Any idea? Thanks in advance
Seems like the package name has been changed from
com.android.phone
to
com.android.server.telecom.
Hope this helps!
An alternative to using the action String manually encoded is to use the default intent like so:
Intent out = new Intent(Intent.ACTION_CALL );
out.setData(Uri.parse("tel:" + Uri.encode("+12345#123")));
startActivity(out);
This will pass the intent to the system and all apps with phone capability will respond instead of the specific one determined via the action String
This means you are trying to call com.android.phone but it's not there. No miracles. It's not gonna work. Either the package is named differently or you are using semi-backed emulator or so with missing stuff. Not to mention you must always have try/catch around startActivity() as there's no guarantee it gonna success (especially when targeting external packages)
This one worked for me on Android 4.4:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setPackage("com.android.dialer");
intent.setData(Uri.parse("tel:1111111111"));
startActivity(intent);
If using Eclipse, open the system dialer app and in DDMS, check for the name of the dialer package; in my case was "com.android.dialer".
Related
I have this code, that works fine in Android 4.4 and previous:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number));
context.startActivity(intent);
Now, in Android 5.0 Lollipop this code doesn't work, and shows this exception:
Fatal Exception: android.content.ActivityNotFoundException
No Activity found to handle Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxx pkg=com.android.phone }
In the documentation, this Intent doesn't appear deprecated:
Any idea? Thanks in advance
Seems like the package name has been changed from
com.android.phone
to
com.android.server.telecom.
Hope this helps!
An alternative to using the action String manually encoded is to use the default intent like so:
Intent out = new Intent(Intent.ACTION_CALL );
out.setData(Uri.parse("tel:" + Uri.encode("+12345#123")));
startActivity(out);
This will pass the intent to the system and all apps with phone capability will respond instead of the specific one determined via the action String
This means you are trying to call com.android.phone but it's not there. No miracles. It's not gonna work. Either the package is named differently or you are using semi-backed emulator or so with missing stuff. Not to mention you must always have try/catch around startActivity() as there's no guarantee it gonna success (especially when targeting external packages)
This one worked for me on Android 4.4:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setPackage("com.android.dialer");
intent.setData(Uri.parse("tel:1111111111"));
startActivity(intent);
If using Eclipse, open the system dialer app and in DDMS, check for the name of the dialer package; in my case was "com.android.dialer".
I have an android application that requires VPN. My users will be using Galaxy Note 3's and will be using the built in "VPN Client" (com.ipsec.vpnclient). I need to find a way to launch this application from my application, in the instance of the VPN dropping. I've already figured out a way to determine if the VPN dropped, but I still need a way to launch the application.
ANSWER:
Thanks to help from #Muthu I was able to get it working with the following method.
final Intent intent = new Intent("android.intent.action.VIEW");
intent.setComponent(new ComponentName("com.ipsec.vpnclient", "com.ipsec.vpnclient.MainActivity"));
EDIT:
To add to the confusion, I am easily able to add a shortcut to the activity (com.ipsec.vpnclient.MainActivity) via another Launcher like ADW or Nova. I also tried using com.ipsec.vpnclient.MainActivity instead of com.ipsec.vpnclient in the method below, to no avail.
Intent intent = getPackageManager().getLaunchIntentForPackage("com.ipsec.vpnclient");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The above method works with other packages, but I can't seem to get this one to launch.
Here is the application when viewed in Android System Info.
Any ideas on how to launch this application programmatically?
You can Start any installed application by using intent. in your case like this
Intent LaunchVPN = getPackageManager().getLaunchIntentForPackage("com.ipsec.vpnclient");
startActivity( LaunchVPN );
Edit
You can open pre installed apps that can be found inside settings page by
final Intent i = new Intent("android.intent.action.VIEW");
i.setComponent(new ComponentName("com.android.settings","com.android.settings.InstalledAppDetails"));
startActivity(i);
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..."));
From within my app, I'd like to start the set up new email account activity of the Email App which looks like this: http://i.stack.imgur.com/BNYnj.png
I've looked at this http://source-android.frandroid.com/packages/apps/Email/AndroidManifest.xml
and tried to start the set up email activity:
Intent intent = new Intent("com.android.email.CREATE_ACCOUNT");
startActivity(intent);
But I got an exception:
E/AndroidRuntime(517): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.email.CREATE_ACCOUNT }
Anyone please help me?
Thanks so much,
John
you could try using an explicit intent. instead of
new Intent("com.android.email.CREATE_ACCOUNT")
use
new Intent(context, com.android.email.activity.setup.AccountSetupBasics.class)
you may also want to look into the whole ACTION_ADD_ACCOUNT action string. it may do what you are looking for without having to use a SPECIFIC app. for example, when an oem installs a different email app from the stock android one. if it happens there won't be anything to handle either the explicity or implicit intent.
This works for from APIs 4.0+.
Intent intent = new Intent("com.android.email.CREATE_ACCOUNT");
intent.putExtra("FLOW_MODE", 0);
startActivity(intent);
Below works for from APIs 2.1+. Maybe also work for lower versions (not tested).
Intent intent = new Intent();
intent.setClassName("com.android.email", "com.android.email.activity.setup.AccountSetupBasics");
intent.putExtra("FLOW_MODE", 0);
startActivity(intent);
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);