Can a telephony.Phone object be instantiated through the sdk?

android

Solution

Yes it can be instantiated. But you have to overcome a couple of hurdles:

In your `AndroidManifest.xml` set

android:sharedUserId="android.uid.phone"

within the `<manifest>` tag. This is required to prevent a `SecurityException` from being thrown when protected Intents are sent by the methods you may invoke (like `android.intent.action.SIM_STATE_CHANGED`).

Set

android:process="com.android.phone"

in your `<application>` tag. This is required to allow the invocation of `getDefaultPhone()` / `makeDefaultPhone()`.

To do all this your app must be signed with the system signature key.

Problem

I am trying to get a phone object so that I can call and conference two numbers from within my application. I have tried using the static `PhoneFactory.makeDefaultPhones((Context)this)` but have not had any luck. ``` String phoneFactoryName = "com.android.internal.telephony.PhoneFactory"; String phoneName = "com.android.internal.telephony.Phone"; Class phoneFactoryClass = Class.forName(phoneFactoryName); Class phoneClass = Class.forName(phoneName); Method getDefaultPhone = phoneFactoryClass.getMethod("getDefaultPhone"); Object phoneObject = getDefaultPhone.invoke(null); ``` Error - Caused by java.lang.RuntimeException: PhoneFactory.getDefaultPhone must be called from Looper thread

Original source