2

I have an application that will run on devices that have phone capabilities and that don't. Here are some of my queries:

1) Will i be able to support both type of devices. 2) For the devices that have phone capabilities, i need to enable calling feature. and the device that do not have phone capabilities i will disable calling functionality.

I am not very clear about the <user-permissions> and <user-features> concept, is there a way to specify phone <user-features>

Avnish
  • 81
  • 1
  • 2
  • 6
  • 3
    `uses-feature`, as far as I know, is only really there to restrict users with insufficient hardware from seeing and downloading your app on android market. In this case, since you want people without calling capabilities to use your app, you would NOT want to require telephony hardware with the `uses-feature` element set as required. – Jon Willis Mar 14 '11 at 04:58

2 Answers2

13

If you're not distributing your app through the Market and if you don't care about following recommended practices, then you should only need <uses-permission> tags for any permissions the app uses. However, to allow the correct devices to access the app through the Market, you will need both <uses-permission> and <uses-feature> tags.

<uses-permission> is a request to give your application the authority to take a certain kind of action. When preparing to install your app, the user can review the requested permissions and decide whether to to continue with the installation. If the app, for example, attempts to make a phone call without declaring the "android.permission.CALL_PHONE" permission, then the attempt will fail. See here for a list of base platform permissions.

<uses-permission> is also used by the Market for implicit feature requirements. If your app uses a permission that needs telephony hardware, then the Market will assume telephony hardware is required, and the app will not be available to a device that lacks telephony hardware.

<uses-feature> can be used to inform the Market either that a certain feature is required or that the feature is desirable but not required. The tag will override any features implied by <uses-permission>. If, for example, you specify <uses-feature android:name="android.hardware.telephony" android:required="false" />, then telephony is not required, regardless of what permissions are requested.

To see how <uses-permission> and <uses-feature> interact to create the Market filters, see here.

To check at run time whether a feature is available, it looks like you can use PackageManager.hasSystemFeature():

Context context;    // Some object, such as Activity, that extends Context
// ...
boolean hasTelephony = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
if (hasTelephony) {
    // ...
}
else {
    // ...
}
erichamion
  • 4,517
  • 1
  • 21
  • 16
  • I want to deploy app through market and still i want to use telephony feature in the device if available and disable calling functionality when device is not capable to make call. – Avnish Mar 14 '11 at 11:00
  • Then you'll need both `` and `` (with android:required="false") tags in the manifest. In your code, something like the sample above with `hasSystemFeature()` should work, although I haven't tried it. – erichamion Mar 14 '11 at 13:21
  • I want to deploy app through market, and i have to support from android 1.5. I think android 1.5 doesn't support "android-required" attribute of uses-feature. It shows "No resource identifier found for attribute 'required' in package 'android'" meassage at compile time. Is there any other way to support this on anddroid-1.5. – Avnish May 26 '11 at 09:34
  • +1 for good explanation and mention about runtime check. Thank you. – Hoang Tran Jul 30 '12 at 09:49
0

Well, i dont know about a really simple way to do it, but you might want to use the method below to get the phone number of the phone and if it returns null, it probably means that phone functions are not available and it is a tablet or something like that (android powered microwave oven? :p )

private String getMyPhoneNumber() {
    TelephonyManager mTelephonyMgr;
    mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    return mTelephonyMgr.getLine1Number();
}

Also , be sure to add the permission "android.permission.READ_PHONE_STATE" on your android manifest file. Good luck :)

KSubedi
  • 443
  • 1
  • 7
  • 17