Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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

like image 830
tsmith Avatar asked Jan 27 '10 00:01

tsmith


2 Answers

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.

like image 131
icyerasor Avatar answered Sep 18 '22 15:09

icyerasor


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

People who want 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).

In short: 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 happy! =) Now my Shake2MuteCall will get an update !

like image 30
foryou Avatar answered Sep 20 '22 15:09

foryou