如何编程隐藏主叫号码在Android上号码、Android

2023-09-14 23:02:33 作者:り 醉染

Android手机,在通话 - >其他设置 - >来电号码

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

就可以隐藏你的来电显示。我想这样做编程方式从我的code,但没能找到一个方法来做到这一点。

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.

我通过

android.provider android.telephony

android.provider android.telephony

对于2.1版本,是不是能够找到它。

for 2.1 release and was not able to find it.

有没有人成功地解决了这个问题?

Has anybody successfully solved this issue?

在此先感谢。最好的问候。

Thanks in advance. Best regards.

推荐答案

下面我将介绍两种方法我试过了。

Here I will describe two approaches I tried.

1)。它可以显示来自应用程序的其它呼叫设置屏幕。虽然它看起来像它的设置应用程序的一部分,这是不正确的。此活动是本机应用程序的一部分,它可以与下面的意图上前:

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);

然后用户必须手动preSS上的来电显示preference,并得到单选按钮带有3种选项。

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)。当方法1下所描述)的本机应用程序执行时,函数 setOutgoingCallerIdDisplay() com.android.internal .telephony.Phone 已被使用。 这是基础,下一个办法:使用Java反射,这个类和尝试调用函数使用适当的参数:

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();                   
}       

首先,我尝试了使用getDefaultPhone(),但我得到的RuntimeException

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

PhoneFactory.getDefaultPhone必须调用由弯针线

"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异常:权限被拒绝:不允许从PID = 2338发送广播android.provider.Telephony.SPN_STRINGS_UPDATED,UID = 10048

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

运行安全的API调用为根,机器人