Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here I will describe two approaches I tried. </p> <p>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:</p> <pre><code>Intent additionalCallSettingsIntent = new Intent("android.intent.action.MAIN"); ComponentName distantActivity = new ComponentName("com.android.phone", "com.android.phone.GsmUmtsAdditionalCallOptions"); additionalCallSettingsIntent.setComponent(distantActivity); startActivity(additionalCallSettingsIntent); </code></pre> <p>Then user has to manually press on the CallerID preference and gets radio button with 3 options. </p> <p>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.</p> <p>2.) When approach described under 1.) is executed in the Native Phone Application, function <code>setOutgoingCallerIdDisplay()</code> from <code>com.android.internal.telephony.Phone</code> 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:</p> <pre><code>try { Class &lt;?&gt; 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 &lt;?&gt; 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(); } </code></pre> <p>Firstly I tried just to use getDefaultPhone(), but I get RuntimeException </p> <p>"PhoneFactory.getDefaultPhone must be called from Looper thread"</p> <p>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.</p> <p>Tried to avoid this by making own default phone, but this was a security violation:</p> <p>ERROR/AndroidRuntime(2338): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.provider.Telephony.SPN_STRINGS_UPDATED from pid=2338, uid=10048</p> <p>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</p> <p><a href="https://stackoverflow.com/questions/6010796/run-secure-api-calls-as-root-android">Run secure API calls as root, android</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload