4

I have heard in many places that if my app uses a permission not applicable to a certain device, it will not show up in the play store for that device. Now, in my code, I am playing audio. I mute that audio whenever there is a phone call by doing this:

 private PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
                if (state == TelephonyManager.CALL_STATE_RINGING) {
                    onPhoneCallInterrupt(); //Method I made that mutes audio for phone call
                } else if (state == TelephonyManager.CALL_STATE_IDLE) {
                } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
                    onPhoneCallInterrupt(); //Method I made that mutes audio for phone call
                }
        }
    };

Now, this uses the following permission in the manifest:

<uses-feature android:name="android.permission.READ_PHONE_STATE"  android:required="false" />

Will I get any exceptions because I have made the permission optional by doing android:required = "false" on devices that don't have phone compatibility (tablets)?

The reason I am so confused on this, is because I am checking if the phone is being used, but I am not using it. So, will my app work on tablets, let alone show up in the play store for them?

Thanks for helping me clear up this confusion,

Ruchir

Xavier Combelle
  • 10,968
  • 5
  • 28
  • 52
Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83

1 Answers1

-2

You have to use this way As your permission READ_PHONE_STATE request the

<uses-feature android:name="android.hardware.telephony" />

So you need to use this

<uses-feature android:name="android.hardware.telephony"
        android:required="false" />

So play store wont filter your apps for the tablets but make sure you have to do check manually where you are using the functionality of the telephony that device is phone or tablets and have a telephony aceess or not

To check the telephony access device has or not use this check this code

static public boolean hasTelephony()
{
    TelephonyManager tm = (TelephonyManager) Hub.MainContext.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm == null)
        return false;

    //devices below are phones only
    if (Utils.getSDKVersion() < 5)
        return true;

    PackageManager pm = MainContext.getPackageManager();

    if (pm == null)
        return false;

    boolean retval = false;
    try
    {
        Class<?> [] parameters = new Class[1];
        parameters[0] = String.class;
        Method method = pm.getClass().getMethod("hasSystemFeature", parameters);
        Object [] parm = new Object[1];
        parm[0] = "android.hardware.telephony";
        Object retValue = method.invoke(pm, parm);
        if (retValue instanceof Boolean)
            retval = ((Boolean) retValue).booleanValue();
        else
            retval = false;
    }
    catch (Exception e)
    {
        retval = false;
    }

    return retval;
}

For more you can check this blog http://commonsware.com/blog/2011/02/25/xoom-permissions-android-market.html

Sandy
  • 985
  • 5
  • 13