tags:

views:

755

answers:

3

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

A: 

I am trying to get a phone object so that I can call and conference two numbers from within my application.

That is not possible from the SDK.

I have tried using the static PhoneFactory.makeDefaultPhones((Context)this) but have not had any luck.

That is not in the SDK. Please do not go past the bounds of the SDK.

Error - Caused by java.lang.RuntimeException: PhoneFactory.getDefaultPhone must be called from Looper thread

That is because you are trying to do the thing-you're-not-supposed-to-be-doing from a background thread.

CommonsWare
I realize that I am not supposed to, however to do the advanced call managing from within my application, none of the public methods will suffice. I want to call two numbers, conference them, and hang up the call when appropriate. Do you have any recommendations on how to do that outside of getting an internal Phone object.
Tyler
A: 

I call it from Activity.onCreate and I crashed several lines after your problem:

IllegalStateException("Default phones haven't been made yet!");

See the Android sources:

public static Phone getDefaultPhone() { if (sLooper != Looper.myLooper()) { throw new RuntimeException( "PhoneFactory.getDefaultPhone must be called from Looper thread"); }

    if (!sMadeDefaults) {
        throw new IllegalStateException("Default phones haven't been made yet!");
    }
   return sProxyPhone;
}
Honza
+1  A: 

Al least we can answer or ignore calls =) let me copy-paste my post

OMG!!! YES, WE CAN DO THAT!!! I was going to kill myself after severe 24 hours of investigating and discovering... But I've found a "fresh" solution!

// "cheat" with Java reflection to gain access to TelephonyManager's ITelephony getter Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); telephonyService = (ITelephony)m.invoke(tm);

all all all of hundreds of people who wants to develop their call-control software visit this start point http://www.google.com/codesearch/p?hl=en#zvQ8rp58BUs/trunk/phone/src/i4nc4mp/myLock/phone/CallPrompt.java&q=itelephony%20package:http://mylockforandroid%5C.googlecode%5C.com&d=0

there is a project. and there are important comments (and credits)

briefly: copy aidl file, add permissions to manifest, copy-paste source for telephony management )))

Some more info for you. AT commands you can send only if you are rooted. Than you can kill system process and send commands but you will need a reboot to allow your phone to receive and send calls =)))

I'm very hapy =) Now my Shake2MuteCall will get an update !

foryou