Hy。我能夠檢索到一個代理電話,這個類已經變成了這個類(並且有點反思)。您可以使用下面的(反射)PhoneFactory:
package your.package;
import java.lang.reflect.Method;
import android.content.Context;
import android.util.Log;
public class ReflectedPhoneFactory {
public static final String TAG = "PHONE";
public static void makeDefaultPhones(Context context) throws IllegalArgumentException {
try{
ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes")
Class PhoneFactory = cl.loadClass("com.android.internal.telephony.PhoneFactory");
//Parameters Types
@SuppressWarnings("rawtypes")
Class[] paramTypes= new Class[1];
paramTypes[0]= Context.class;
Method get = PhoneFactory.getMethod("makeDefaultPhone", paramTypes);
//Parameters
Object[] params= new Object[1];
params[0]= context;
get.invoke(null, params);
}catch(IllegalArgumentException iAE){
throw iAE;
}catch(Exception e){
Log.e(TAG, "makeDefaultPhones", e);
}
}
public static void makeDefaultPhone(Context context) throws IllegalArgumentException {
try{
ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes")
Class PhoneFactory = cl.loadClass("com.android.internal.telephony.PhoneFactory");
//Parameters Types
@SuppressWarnings("rawtypes")
Class[] paramTypes= new Class[1];
paramTypes[0]= Context.class;
Method get = PhoneFactory.getMethod("makeDefaultPhone", paramTypes);
//Parameters
Object[] params= new Object[1];
params[0]= context;
get.invoke(null, params);
}catch(IllegalArgumentException iAE){
throw iAE;
}catch(Exception e){
Log.e(TAG, "makeDefaultPhone", e);
}
}
/*
* This function returns the type of the phone, depending
* on the network mode.
*
* @param network mode
* @return Phone Type
*/
public static Integer getPhoneType(Context context, int networkMode) throws IllegalArgumentException {
Integer ret= -1;
try{
ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes")
Class PhoneFactory = cl.loadClass("com.android.internal.telephony.PhoneFactory");
//Parameters Types
@SuppressWarnings("rawtypes")
Class[] paramTypes= new Class[1];
paramTypes[0]= Integer.class;
Method get = PhoneFactory.getMethod("getPhoneType", paramTypes);
//Parameters
Object[] params= new Object[1];
params[0]= new Integer(networkMode);
ret= (Integer) get.invoke(PhoneFactory, params);
}catch(IllegalArgumentException iAE){
throw iAE;
}catch(Exception e){
ret= -1;
}
return ret;
}
public static Object getDefaultPhone(Context context) throws IllegalArgumentException {
Object ret= null;
try{
ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes")
Class PhoneFactory = cl.loadClass("com.android.internal.telephony.PhoneFactory");
Method get = PhoneFactory.getMethod("getDefaultPhone", (Class[]) null);
ret= (Object)get.invoke(null, (Object[]) null);
}catch(IllegalArgumentException iAE){
throw iAE;
}catch(Exception e){
Log.e(TAG, "getDefaultPhone", e);
}
return ret;
}
public static Phone getCdmaPhone(Context context) throws IllegalArgumentException {
Phone ret= null;
try{
ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes")
Class PhoneFactory = cl.loadClass("com.android.internal.telephony.PhoneFactory");
Method get = PhoneFactory.getMethod("getCdmaPhone", (Class[]) null);
ret= (Phone)get.invoke(null, (Object[]) null);
}catch(IllegalArgumentException iAE){
throw iAE;
}catch(Exception e){
//
}
return ret;
}
public static Phone getGsmPhone(Context context) throws IllegalArgumentException {
Phone ret= null;
try{
ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes")
Class PhoneFactory = cl.loadClass("com.android.internal.telephony.PhoneFactory");
Method get = PhoneFactory.getMethod("getGsmPhone", (Class[]) null);
ret= (Phone)get.invoke(null, (Object[]) null);
}catch(IllegalArgumentException iAE){
throw iAE;
}catch(Exception e){
//
}
return ret;
}
}
有了它,使用代碼:
ReflectedPhoneFactory.makeDefaultPhone(yourContext);
Object phoneProxy= ReflectedPhoneFactory.getDefaultPhone(yourContext);
注意「makeDefaultPhone」通話將更新靜態成員「靜態專用尺蠖的價值sLooper;」我還沒有測試過附帶效應。
使用收到的「phoneProxy」對象,您可以使PhoneProxy呼叫進行反射。 (我目前正在實現這個類,並且可能會發布它,如果認爲有用的話。
這可能很明顯,但由於'PhoneFactory'不在SDK中,所以您可能不想使用它:) – 2010-01-27 02:38:54
運行此代碼時,出現'InvocationTargetException' 'getDefaultPhone.invoke(空)'。我也嘗試過使用'getDefaultPhone.setAccessible(true)'在它之前,但是沒有效果。 – 2011-01-25 13:06:03
@Tyler我必須從我的應用程序發起電話會議。如果你發現任何解決方案.pls在這裏回答 – 2011-08-27 09:16:53