1

Androidで着信を操作する必要があります。このコードを取得しました:

public class Metdllamadas extends Activity{

private static final String TAG = "Debug";
Integer Metodo1=0;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_metdllamadas);
    Bundle extras = getIntent().getExtras();
    try
    {
    Metodo1 = Integer.parseInt(extras.getString("Metodo"));

    }catch(NullPointerException npe)
    {
        Metodo1=2;


    }
    Toast.makeText(getApplicationContext(),Metodo1.toString(), Toast.LENGTH_LONG).show();
 TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

try {
    //String serviceManagerName = "android.os.IServiceManager";
    String serviceManagerName = "android.os.ServiceManager";
    String serviceManagerNativeName = "android.os.ServiceManagerNative";
    String telephonyName = "com.android.internal.telephony.ITelephony";

    Class telephonyClass;
    Class telephonyStubClass;
    Class serviceManagerClass;
    Class serviceManagerStubClass;
    Class serviceManagerNativeClass;
    Class serviceManagerNativeStubClass;

    Method telephonyCall;
    Method telephonyEndCall;
    Method telephonyAnswerCall;
    Method getDefault;

    Method[] temps;
    Constructor[] serviceManagerConstructor;

    // Method getService;
    Object telephonyObject;
    Object serviceManagerObject;

    telephonyClass = Class.forName(telephonyName);
    telephonyStubClass = telephonyClass.getClasses()[0];
    serviceManagerClass = Class.forName(serviceManagerName);
    serviceManagerNativeClass = Class.forName(serviceManagerNativeName);

    Method getService = // getDefaults[29];
    serviceManagerClass.getMethod("getService", String.class);

    Method tempInterfaceMethod = serviceManagerNativeClass.getMethod("asInterface", IBinder.class);

    Binder tmpBinder = new Binder();
    tmpBinder.attachInterface(null, "fake");

    serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder);
    IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone");
    Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class);

    telephonyObject = serviceMethod.invoke(null, retbinder);
    telephonyCall = telephonyClass.getMethod("call", String.class);
    telephonyEndCall = telephonyClass.getMethod("endCall");
    telephonyAnswerCall = telephonyClass.getMethod("answerRingingCall");

    if (Metodo1==2)
    {
        Toast.makeText(getApplicationContext(), "Terminando Llamada", Toast.LENGTH_LONG).show();
    telephonyEndCall.invoke(telephonyObject);
    }

} catch (Exception e) {
    e.printStackTrace();
    // Log.error(DialerActivity.this,"FATAL ERROR: could not connect to telephony subsystem");
    //Log.error(DialerActivity.this, "Exception object: " + e);
}



finish();
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.metdllamadas, menu);
    return true;
}

}

アクティビティがパラメーター「Metodo」を指定する別のアクティビティから起動されたとします。Metodo1 = 2 の場合、呼び出しを終了 (または拒否) する必要があります。Metodo1 = 1 の場合、呼び出しに応答する必要があり、Metodo1 = 3 の場合、応答する必要があります。スピーカー付き。

4

0 に答える 0