I am trying to call a USSD number from my application like this:
Uri u = Uri.fromParts("tel", "*110#", "");
Intent i = new Intent(Intent.ACTION_CALL, u);
startActivity(i);
This makes the phone app launch and call the number.
What I want is to call the USSD number without opening the phone app or atlease open it up in the background.
If the user is doing something, then he should not be disturbed. Only a notification must be generated.
any suggestions?
it is possible now since android O(api 26) with sendUssdRequest() check the docs https://developer.android.com/reference/android/telephony/TelephonyManager.html#sendUssdRequest(java.lang.String,%20android.telephony.TelephonyManager.UssdResponseCallback,%20android.os.Handler)
Related
I am trying to write a code to whatsapp call a mobile number, without saving it to the phonebook.
I have written the code as:
Intent callIntent = new Intent("android.intent.action.MAIN");
callIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
callIntent.putExtra("jid", "19876543210#s.whatsapp.net");//phone number without "+" prefix
callIntent.putExtra(Intent.EXTRA_TEXT, "voip-call");
callIntent.putExtra("call", true);
callIntent.setAction(Intent.ACTION_CALL);
callIntent.setPackage("com.whatsapp");
startActivity(callIntent);
But it is not working.
Any sort of help would be beneficial for my learning.
Am developing functionality in which i wanted to Intent.ACTION_DIAL.
Below is the code which i have tried so far.
Intent callIntent = new Intent(Intent.ACTION_DIAL);
String str = "tel:xxxxxxxxxx"; callIntent.setData(Uri.parse(str));
context.startActivity(callIntent);
However facing below two problems
1) if i tried to retrieve the imei number using "tel:#06#" then it will open the device dialer with '' only. "#06#" is not appearing there.
2) It asks the user to press call button. I dont want user to press the call button. is there any API which will allow me to directly execute "tel"*#06# kind of code from application itself.
EDITED:
I have tried below answer. its invoking dialer with "*#06#" but not showing the IMEI number of the device. if i press the same from device dialer and it showing IMEI number instantly.
All i want is to show the IMEI kind of codes from Application.
Intent callIntent = new Intent(Intent.ACTION_CALL);
String encodedHash = Uri.encode("#");
String ussd = encodedHash + "06" + encodedHash;
startActivityForResult(new Intent("android.intent.action.CALL",
Uri.parse("tel:" + ussd)), 1);
and give this permission in android menifest
<uses-permission android:name="android.permission.CALL_PHONE" />
I'm trying to call a complex number with the ACTION_CALL intent, similar to a calling card. It looks something like this: (Calling card phone number, calling card pin, actual number to dial.)
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:18005551234,987654#,14325558765");
startActivity(callIntent);
However, when the dialer comes up, it only dials the 800 number at the start of the sequence and ignores the rest.
How can I get it to dial the entire number?
It appears this works if you encode the number.
String num = "tel:"+Uri.encode("18005551234,987654#,14325558765");
Note that including "tel:" inside the Uri.encode() call also encodes the :, which breaks the URI.
I would like to start a default application: browser, contact-book, phone, email, music app, etc. I have found many q/a, like browser opening a specific URL or blank, and here the answer is even "No not possible". But I would like to just open/launch it without telling it to go to a specific URL or sending a mail to someone, etc.
However, I also saw some Home applications where this seems to be working (at least for some apps). On my colleague's device there is for example a different contact-book (no google) which is detected and opened correctly.
I have seen in the Android documentation some intent categories that point to these problems, but these are only >= API.11. So I can't use/test them on my device.
Question: Is it not somehow possible to launch a default application (having the app chooser is of course ok) without providing extra data? If no, what do you think are these Home apps doing (perhaps workarounds are somehow possible).
PS: for the phone app I think, I have a workaround using Intent.ACTION_DIAL without any other information which will open simply the dialer.
UPDATE: I modified the title. Some applications like the address book may not be the same on different devices. So in this case I would like to start the address-book app, whichever this is.
This answer is not a 100% answer, but some workarounds on some typical applications.
Still open are: music player, address book
Browser: I get a list of applications that handle "http"-data intents, and then I look if one is available in the list of preferred applications.
Intent appFilter = new Intent(Intent.ACTION_VIEW);
appFilter.setData(Uri.parse("http://www.google.com"));
List<ResolveInfo> browserInfoList = pm.queryIntentActivities(appFilter, 0);
List<IntentFilter> outFilters = new ArrayList<IntentFilter>();
List<ComponentName> outActivities = new ArrayList<ComponentName>();
pm.getPreferredActivities(outFilters, outActivities, null);
if(outActivities.size() > 0) {
for(ComponentName cn : outActivities) {
String cnClass = cn.getClassName();
String cnPkg = cn.getPackageName();
for (ResolveInfo info : browserInfoList) {
if(info.activityInfo.name.equals(cnClass) &&
info.activityInfo.packageName.equals(cnPkg)) {
return cn;
}
}
}
}
In case no default is found, I open a browser chooser dialog, see here.
Phone: as described in the question:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
You can start apps by the function "startActivity" if you know about the canonical app name
like "android.com.browser". Do this simple by searching for AndroidManifest.xml in the app
source code (look at Codeaurora.com or at github/Cyanogenmod) and grab the app name you want.
After you know about the App name ("Activity") implement the code as follows:
Intent intent = new Intent();
intent.setClassName(this, "com.android.browser");
intent.setCategory(Intent.ACTION_MAIN);
startActivity(intent);
THIS is only a example, sometimes you have to put intent extras or data values, this information can be found in the app's AndroidManifest.xml too.
I would like to forward all calls to my number on to the new predefined number
automatically. Is it possible to forward incoming call ?
Probably it is possible for Froyo at least. I found application called Easy Call Forwarding.
http://www.appstorehq.com/easycallforwarding-android-189596/app
But many people reckon it doesn't work actually.
We can notice forwarded call by onCallForwardingIndicatorChanged() from PhoneStateListener but
I have no idea how to set forwarding mode.
I explored on the net and got the answer to my question that how one can forward a call programmatically. Add these lines of code and one will be able to achieve it.
String callForwardString = "**21*1234567890#";
Intent intentCallForward = new Intent(Intent.ACTION_DIAL); // ACTION_CALL
Uri uri2 = Uri.fromParts("tel", callForwardString, "#");
intentCallForward.setData(uri2);
startActivity(intentCallForward);
Here 1234567890 represents the phone number. Add the approriate phone number as you wish here. One can dial ##21# to deactivate the service.
My solution:
Intent intent = new Intent(Intent.ACTION_CALL);
String prefix = "#31#";
prefix = Uri.encode(prefix);
intent.setData( Uri.parse("tel:"+prefix+"123456"));
startActivity(intent);