Hy. Tôi đã có thể lấy một ProxyPhone trought lớp này (và một chút phản ánh). Bạn có thể sử dụng PhoneFactory (Reflected) dưới đây:
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;
}
}
Với nó, sử dụng mã:
ReflectedPhoneFactory.makeDefaultPhone(yourContext);
Object phoneProxy= ReflectedPhoneFactory.getDefaultPhone(yourContext);
Lưu ý rằng "makeDefaultPhone" cuộc gọi sẽ cập nhật giá trị của các thành viên tĩnh "tĩnh tin Looper sLooper; " và tôi chưa thử nghiệm các hiệu ứng thế chấp.
Với đối tượng "phoneProxy" đã nhận, bạn có thể thực hiện phản chiếu trêu chọc của cuộc gọi PhoneProxy. (Tôi hiện đang triển khai lớp này và có thể đăng bài nếu được xem là hữu ích.
Điều này có thể hiển nhiên nhưng vì 'PhoneFactory' không có trong SDK, bạn có thể không muốn sử dụng nó :) –
Khi chạy mã này, tôi nhận được' InvocationTargetException' trên 'getDefaultPhone.invoke (null)'. Tôi cũng đã thử trước nó với 'getDefaultPhone.setAccessible (true)', nhưng điều đó không có hiệu lực. –
@Tyler tôi phải khởi chạy cuộc gọi hội nghị từ ứng dụng của mình. nếu bạn tìm thấy bất kỳ giải pháp .pls trả lời ở đây –