I tried to make a call when I click on Android Mobile field with this code
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+contactNo));
startActivity(callIntent);
And added these in AndroidManifest.xml
<uses-permission android:name="packagename.permission.C2D_MESSAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
And finally I am getting **java.lang.SecurityException** exception.
Why it Happens? and What is the Correct Procedure to Make a Call when click on Contact field?
use Intent.ACTION_DIAL instead of Intent.ACTION_CALL
And action_dial does not need permission, and it will show dialed phone number to user on dialer and then it will be users wish to place a call or not. This will be better approach to give user a control of what they wants to do.
hope that will help you
In order to use Intent.ACTION_CALL you have to add a permission to your manifest.
Add this permission to your manifest and it should be ok
<uses-permission android:name="android.permission.CALL_PHONE"/>
Related
This is an example of a code for creating a direct shortcut that calls a specific number and which works on Android M and below.
public void installShortcutGetId(){
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"MyCallShortcut");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_CALL, Uri.parse("tel:77777777")));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, android.R.drawable.sym_def_app_icon));
context.sendBroadcast(intent);
}
The same code doesn't work anymore on Android N, I can see in the logcat the following:
/com.android.launcher3 E/InstallShortcutReceiver: Ignoring malicious intent tel:77777777#Intent;action=android.intent.action.CALL;end
If I change ACTION_CALL to ACTION_DIAL, it works on Android N but that's not what I am looking for. I am looking for a way to make a direct call through the shortcut.
In terms of permissions, I have these 2 included and CALL_PHONE requested at run-time.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.CALL_PHONE" />
Just because your app has the CALL_PHONE permission doesn't mean the launcher has that permission: that's why your shortcut cannot be created.
You could instead create a shortcut to an empty activity of your own and start the ACTION_CALL Intent from that activity.
I'm trying to write an app that, among other things, calls people. To do this, I use the following code:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + number));
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
The problem is: When I run it, it shows me a dialog and I need to choose with which app I want to make the call (Skype/Viber/Dialer/etc.). How can I make the call immediately using the standard dialer (without the dialog showing up)?
The difference between Intent.ACTION_DIAL and Intent.ACTION_CALL is that the first one allows the user to explicitly initiate the call showing the dialer UI. When using ACTION_CALL, a pop-up will open and let you choose which dialer to use.
Also, add permission on your manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
I have a class that makes a call to an emergency number. I get to the "call" app with the phone number already passed in, but i still have to press the Call Button to start the call.
Is there a possibility where i don't actively have to press the call button but it does it automatically?
Emergency numbers always require that the user presses a button explicitly. This is a security feature.
See docu for ACTION_CALL
As henry has mentioned in his answer, its only possible call emmergency number using ACTION_DIAL. Howerver you can call anyother number directly using this intent.
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "ur phoneNumber here"));
startActivity(intent);
Dont Forget to Add this Permission to the Manifest :
<uses-permission android:name="android.permission.CALL_PHONE" />
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);
Permission required is
<uses-permission android:name="android.permission.CALL_PHONE" />
I start a call intent like this :
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+numberToCall));
startActivity(callIntent);
but instead of directly calling that number I see the calling screen with the number prefilled and I have to press the call button in order to call. Is it possible to call directly without having to press the call button?
Thanks
Add this to your manifest. It will allow you to call a phone without prompt
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
CALL_PHONE: Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.
Which can be found here:
http://developer.android.com/reference/android/Manifest.permission.html
You can dial number by using the CALL_PHONE permission. For other, privileged, numbers use the CALL_PRIVILEGED permissison.
I am developing an app and in the manifest I have:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
When I click on the button to execute this code:
Intent intentcall = new Intent();
intentcall.setAction(Intent.ACTION_CALL);
intentcall.setData(Uri.parse("tel:" + phonenumber)); // set the Uri
startActivity(intentcall);
It will run fine on phones, and on tablets it pops up with a display where you can view or add the number to contacts. However, if I keep the permission in the manifest, it isn't available for tablets in the market. How can I keep the code behavior and still have it display in the market for tablets as well as phones?
In the AndroidManifest you need:
<uses-feature android:name="android.hardware.telephony" android:required="false" />
The CALL_PHONE permission implies telephony is required, but if you specify that is not you won't be filtered.
Try to use Intent.ACTION_DIAL instead Intent.ACTION_CALL.
For example:
try {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone_number));
startActivity(intent);
} catch (Exception e) {
//TODO smth
}
And in this case you can completely remove these tags from AndroidManifest.xml:
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-feature android:name="android.hardware.telephony" android:required="false" />
Regarding "uses-feature" and it crashing - are you checking that telephony is available before actually making the call? It might be you need to do that extra step for the case when the app is on tablets. All you are saying in the manifest is that the feature is not required. It probably relies on you to actually implement the logic around that.
Instead of adding a user with the ACTION_CALL identifier, change it to ACTION_INSERT_OR_EDIT.
You'll need these permissions too, instead of the CALL_PHONE permission:
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>
Take a look at this related question:
can't find app on market
From google docs:
Declared elements are informational only, meaning that
the Android system itself does not check for matching feature support
on the device before installing an application
usage is only for google play