android.permission.CALL_PHONE for tablets

2019-01-11 03:27发布

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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" />


回答4:

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



回答5:

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