39

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?

mouser58907
  • 797
  • 2
  • 10
  • 21

5 Answers5

62

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.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Kevin TeslaCoil
  • 10,037
  • 1
  • 39
  • 33
  • 2
    I guess I failed to mention that if I do this the above code causes a crash when the button is clicked. – mouser58907 Oct 25 '11 at 03:16
  • @Kevin, the application won't be filtered, but whenever app tries to use the call feature, Android throws a java.lang.SecurityException: Permission Denial: starting Intent (...) requires android.permission.CALL_PHONE – pandre Nov 24 '11 at 15:27
  • 1
    You still need to add the CALL_PHONE permission, but setting the uses-feature as above allows that to be optional so you can still download it on wifi devices (e.g. tablets). – Dan J Dec 13 '11 at 00:39
39

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" />
valerybodak
  • 4,195
  • 2
  • 42
  • 53
6

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.

user655489
  • 1,316
  • 3
  • 14
  • 21
  • I thought I was checking correctly, could you elaborate on how to properly check? – mouser58907 Dec 05 '11 at 17:05
  • 2
    well, I had to check what I was doing... I was initially doing this: boolean hasPhone = getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY); but I have a note to myself that this might flaky on some phones. What are you using – user655489 Dec 05 '11 at 23:50
  • I think I was using checkPermission(__, __). I'll try this out when I can get my hands on an Android Phone and report back. – mouser58907 Dec 07 '11 at 23:45
  • 1
    Try catching SecurityException maybe? – Jarek Potiuk Mar 24 '12 at 00:26
3

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

Community
  • 1
  • 1
John Leehey
  • 22,052
  • 8
  • 61
  • 88
  • The thing is I still want to Call them if possible. However, the tablet seems to have taken this into account and launched its own intent to display and save the contact if I use ACTION_CALL. – mouser58907 Oct 24 '11 at 23:22
  • 1
    The market filters applications based on attributes, so as long as the CALL_PHONE permission is present, you won't be able to make this app available to tablets on the market. You will probably need to make a separate application for tablets if you want it to be available. – John Leehey Oct 24 '11 at 23:24
  • That is strange because it behaves so well when I run it on my Xoom from eclipse. – mouser58907 Oct 24 '11 at 23:27
  • I'm guessing that android anticipated the testing of certain functions on devices that don't actually support those functions, and mapped them to other areas. I do think they try to require the functionality of the program to only do exactly what the user intended, and sending an intent to call someone and have an add contact screen popup is in most cases not what the user intends to do. My guess is that this is one of the reasons they apply these filters to the market. – John Leehey Oct 25 '11 at 17:42
0

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

Bush
  • 2,433
  • 5
  • 34
  • 57