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

前端 未结 6 1619
我在风中等你
我在风中等你 2020-12-04 18:43

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.makeDefa

6条回答
  •  感动是毒
    2020-12-04 19:20

    Hy. I was able to retrieve an ProxyPhone trought this class ( and a little bit of reflection ). You may use the (Reflected)PhoneFactory below:

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

    With it, use the code:

            ReflectedPhoneFactory.makeDefaultPhone(yourContext);
            Object phoneProxy= ReflectedPhoneFactory.getDefaultPhone(yourContext);
    

    Note that the "makeDefaultPhone" call will update the value of the static member "static private Looper sLooper;" and i did not yet tested for collateral effects.

    With the received "phoneProxy" object you may make the PhoneProxy call´s trought reflection. ( I am currently implementing this class and may post it if considered useful.

提交回复
热议问题