Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically hide Caller ID on Android

Tags:

android

on Android phones, under Call -> Additional settings -> Caller ID

it is possible to hide your caller ID. I want to do that programatically from my code, but was not able to find a way to do that.

I searched through

android.provider android.telephony

for 2.1 release and was not able to find it.

Has anybody successfully solved this issue?

Thanks in advance. Best regards.

like image 467
Zelimir Avatar asked Aug 18 '10 09:08

Zelimir


People also ask

How do I make my caller ID invisible?

Use *67 to hide your phone number This trick works for smartphones and landlines. Open your phone's keypad and dial * - 6 - 7, followed by the number you're trying to call.

Can you disguise your caller ID?

Click on Additional settings. Click on Caller ID. Choose Hide number and your number will be hidden.

How do I temporarily disable caller ID?

This should also work on Android phones, but changing hiding your caller ID in settings may be different. Open the Phone app tap on Keypad. Dial *67 before the number you want to call. The receiver will not be able to see your phone number, and will see "No Caller ID," "Private," or "Blocked."


1 Answers

Here I will describe two approaches I tried.

1.) It is possible to display Additional Call Settings screen from your application. Although it looks like it is part of the Settings application, that is not true. This Activity is part of the Native Phone Application, and it may be approached with the following intent:

Intent additionalCallSettingsIntent = new Intent("android.intent.action.MAIN");
ComponentName distantActivity = new ComponentName("com.android.phone", "com.android.phone.GsmUmtsAdditionalCallOptions");
additionalCallSettingsIntent.setComponent(distantActivity);
startActivity(additionalCallSettingsIntent);

Then user has to manually press on the CallerID preference and gets radio button with 3 options.

This was not actually what I wanted to achieve when I asked this question. I wanted to avoid step where user has to select any further options.

2.) When approach described under 1.) is executed in the Native Phone Application, function setOutgoingCallerIdDisplay() from com.android.internal.telephony.Phone has been used. This was the basis for the next approach: use Java Reflection on this class and try to invoke the function with appropriate parameters:

try 
{
    Class <?> phoneFactoryClass = Class.forName("com.android.internal.telephony.PhoneFactory");

    try
    {
        Method getDefaultPhoneMethod = phoneFactoryClass.getDeclaredMethod("getDefaultPhone");              
        Method makeDefaultPhoneMethod = phoneFactoryClass.getMethod("makeDefaultPhone" , Context.class);                

        try
        {                       
            makeDefaultPhoneMethod.invoke(null, this);
            Object defaultPhone = getDefaultPhoneMethod.invoke(null);

            Class <?> phoneInterface = Class.forName("com.android.internal.telephony.Phone");
            Method getPhoneServiceMethod = phoneInterface.getMethod("setOutgoingCallerIdDisplay", int.class, Message.class);

            getPhoneServiceMethod.invoke(defaultPhone, 1, null);                    
        }
        catch (InvocationTargetException ex) 
        {
            ex.printStackTrace();                   
        }
        catch (IllegalAccessException ex) 
        {
            ex.printStackTrace();                   
        }       
    }
    catch (NoSuchMethodException ex) 
    {
        ex.printStackTrace();                   
    }           
}
catch (ClassNotFoundException ex) 
{
    ex.printStackTrace();                   
}       

Firstly I tried just to use getDefaultPhone(), but I get RuntimeException

"PhoneFactory.getDefaultPhone must be called from Looper thread"

Obviously, issue lies in the fact that I tried to call this method from the Message Loop that was not the Native Phone App one.

Tried to avoid this by making own default phone, but this was a security violation:

ERROR/AndroidRuntime(2338): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.provider.Telephony.SPN_STRINGS_UPDATED from pid=2338, uid=10048

The only way to overcome (both of) this would be to sign your app with the same key as the core systems app, as described under

Run secure API calls as root, android

like image 144
Zelimir Avatar answered Nov 02 '22 18:11

Zelimir