How can I make a call without/with user interaction.
I found the intent Intent.ACTION_CALL on the internet, but I want to write program like the one which initiates a call in response of this intent, is this possible? If this is possible, then how can I do this?
I do not want to initiate a dialog to dial for a call, I want to internally make a call in my application.
Is there any java library, which I can use for this purpose?
Use Intent. That's how it is designed to work in Android:
try {
startActivity(new Intent(Intent.ACTION_CALL,
Uri.parse("tel:PHONE_NUMBER_HERE" )));
} catch (Exception e) {
e.printStackTrace();
}
This will start dialing.
That is not possible from an SDK application.You have to use Intent.ACTION_CALL.
Related
I'm looking for a way to open a browser at a specific link automatically at a give time / daily.
Maybe there is some kind of script, add-on for bowser but I still haven't find one.
Does anyone know a good solution?
I suggest you to use an AalarmManager here is an example
And then here is the code you should execute
String urlString = "your_url";
Intent intent = new
Intent(Intent.ACTION_VIEW,Uri.parse(urlString));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
try {
context.startActivity(intent);
}
catch (ActivityNotFoundException ex) {
context.startActivity(intent);
}
Seems to me this is a combination of three things, setting the alarm, firing the intent and making sure the intent has the data to open a specific uri in the browser.
start activity from an alarm
open a uri
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
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();
}
I am able to create an Activity that uses the DevicePolicyManager API's.
The tutorials show that I need use it the following fashion:
if (!mDPM.isAdminActive(mAdminName)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
intent.putExtra("wipe-data", DeviceAdminInfo.USES_POLICY_WIPE_DATA);
startActivityForResult(intent, REQUEST_ENABLE);
}
else {
mDPM.wipeData(0);
}
However I would like this to run inside a Service.
But I cant call
startActivityForResult
from within a Service.
So what would be the best approach or strategy for me to try ?
The only reason you need to call startActivityForResult() is if your app is not presently configured as a device administrator, to lead the user to go set that up for you. Hence, put that portion of your logic inside of your user interface.
Your service itself would just skip doing anything if isAdminActive() returns false.
I am developing an app were i need to use some sort of method to handel two different intents from a click of a Button. The first is only sometimes able to start without crashing the app. Therfore i need to start another intent were the app normally would have crashed.
Better explained do I need some sort of method that launches another intent, if the 1. intent can not start a new activity, then start the 2 intent.
I really appreciate some sort of formula, instead of a link or reference.
You are looking for a try catch block.
try
{
startActivity(intent);
}
catch(Exception e)
{
startActivity(another_intent);
}
Try/Catch in your code. You can then launch another intent if the first one fails.
If your application is crashing, you should sort this out. You wont be able to start another intent if the application crashes though, because the Applications Process has been killed by the OS. You will need to detect if you can launch the activity, otherwise launch another.
Fix the crash, then implement some switching logic based on what used to be causing a crash.