Pode um telefone.O objecto do telefone foi instanciado através do sdk?

Estou a tentar arranjar um objecto de telefone para poder ligar e comunicar dois números dentro da minha candidatura.

tentei usar a estática PhoneFactory.makeDefaultPhones((Context)this) mas não tive qualquer sorte.

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

erro causado por java.idioma.RuntimeException: PhoneFactory.getDefaultPhone deve ser chamado de Looper thread

 14
Author: The Vee, 2010-01-27

6 answers

Sim, pode ser instanciado. Mas tens de ultrapassar alguns obstáculos.
  • No seu conjunto AndroidManifest.xml

    Android: sharedUserId = " android.liquido.telefone "

    Dentro da etiqueta <manifest>. Isto é necessário para evitar que um SecurityException seja lançado quando os intentos protegidos são enviados pelos métodos que você pode invocar (como android.intent.action.SIM_STATE_CHANGED).

  • Conjunto

    Android: process= " com.androide.telefone "

    Na tua etiqueta <application>. Isto é necessário para permitir a invocação de getDefaultPhone() / makeDefaultPhone().

  • Para fazer tudo isso, seu aplicativo deve ser assinado com a chave de assinatura do sistema.

 11
Author: icyerasor, 2016-10-17 13:41:01

Ao menos podemos responder ou ignorar chamadas =) deixe-me copiar o meu post

Meu Deus!!! SIM, PODEMOS FAZER ISSO!!!
Eu ia matar-me depois de 24 horas de investigação e descoberta... Mas encontrei uma solução "fresca"!
// "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);
As pessoas que querem desenvolver o seu software de controlo de chamadas visitam este início. ponto: 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 Há um projecto. e há comentários importantes (e créditos).

Em resumo: copy AIDL file, add permissions to manifest, copy-paste source for telephony management.

Mais informações para si. AT comandos que você pode enviar apenas se você está enraizado. Do que você pode matar o sistema processar e enviar comandos, mas você vai precisar de um reboot para permitir que o seu telefone para receber e enviar chamadas. Estou muito feliz! Agora o meu Shake2MuteCall vai ter uma actualização !
 4
Author: foryou, 2011-01-25 11:48:44

Hy. Eu era capaz de recuperar um ProxyPhone traught esta classe (e um pouco de reflexão ). Você pode usar o Fonefactory (refletido)abaixo:

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;

}
}

Com ele, use o código:

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

Note que a chamada" makeDefaultPhone "irá actualizar o valor do membro estático" static private Looper sLooper; " e eu ainda não testei os efeitos colaterais.

Com o objecto "foneproxy" recebido, pode fazer o Foneproxy chamar reflexão. (I am currently implementar esta classe e pode postá-la se considerado útil.

 2
Author: Void, 2012-01-10 19:30:59
Estou a tentar arranjar um objecto de telefone. que eu possa chamar e conferência dois números de dentro da minha candidatura.

Isso não é possível pelo SDK.

Eu tentei usar a estática. Fonefactory.makeDefaultPhones ((contexto)this) mas não tive sorte.
Isso não está no SDK. Por favor não passes dos limites do SDK.

Erro causado por hipoteca.idioma.Introdução: Fonefactory.getDefaultPhone deve ser chamada de Looper thread ([3])

Isso é porque estás a tentar fazer aquilo que não devias estar a fazer a partir de um fio de fundo.
 0
Author: CommonsWare, 2010-01-27 13:56:54
Liguei-lhe da actividade.onCreate e estoirou várias linhas após o seu problema com o seguinte erro:

Os telefones por omissão ainda não foram feitos!

Veja as fontes Android:

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;
}
 0
Author: Honza, 2011-01-25 13:08:42

Para tua informação, o telefone interno das classes, o CallManager e alguns outros são deslocados de /system/framework/framework.jar to / system/framework / telephony-common.jar in Jelly bean.

 0
Author: slash33, 2013-05-28 07:50:27