2012-06-02 8 views
10

Quando inserisco un numero qualsiasi nella tastiera e dopo quando preme il pulsante di chiamata prima che il telefono effettui la chiamata, voglio ottenere quel numero di selezione in logcat.Recupera il numero di composizione durante la chiamata.

Vedere sotto Immagine per capire.

enter image description here

Posso avere il numero al momento della chiamata, se sì, allora come posso?

+1

Prova sovrascrivendo il ** ** chiamata pulsante evento Pressione – Lucifer

risposta

5

Hey Infine ho ottenuto una soluzione per questo .. come questo si può anche ottenere che.

è necessario utilizzare ITelephony.aidl file in questo modo:

package com.android.internal.telephony; 

import android.os.Bundle; 
     interface ITelephony { 
     boolean endCall(); 
     void dial(String number); 
     void answerRingingCall(); 
     void abortCall(); 
    } 

E In OutgoingCallReceiver

public class OutgoingCallReceiver extends BroadcastReceiver { 

    Context context = null; 
    private static final String TAG = "Phone call"; 
    private ITelephony telephonyService; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Bundle bundle = intent.getExtras(); 

     if (null == bundle) 
      return; 

     String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 

     Log.i("OutgoingCallReceiver", phonenumber); 
     Log.i("OutgoingCallReceiver", bundle.toString()); 

     String info = "Detect Calls sample application\nOutgoing number: "+ phonenumber; 
     /* System.out.println("value id:"+info); */ 
     Toast.makeText(context, info, Toast.LENGTH_LONG).show(); 

     TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
     try { 
      Class c = Class.forName(telephony.getClass().getName()); 
      Method m = c.getDeclaredMethod("getITelephony"); 
      m.setAccessible(true); 
      /* 
      * com.android.internal.telephony.ITelephony telephonyService = 
      * (ITelephony) m.invoke(tm); 
      */ 
      telephonyService = (ITelephony) m.invoke(telephony); 
      telephonyService.answerRingingCall(); 
      telephonyService.endCall(); 
      telephonyService.dial(null); 
      telephonyService.abortCall(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 
} 

E se si desidera ottenere IncomingCallReceiver allora come non è possibile:

public class IncomingCallReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
      Bundle bundle = intent.getExtras(); 

      if(null == bundle) 
        return; 

      Log.i("IncomingCallReceiver",bundle.toString()); 
      String state = bundle.getString(TelephonyManager.EXTRA_STATE); 
      Log.i("IncomingCallReceiver","State: "+ state); 
      if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) 
      { 
        String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); 
        Log.i("IncomingCallReceiver","Incomng Number: " + phonenumber); 
        System.out.println("Coming in Incoming Number"+phonenumber); 
        String info = "Detect Calls sample application\nIncoming number: " + phonenumber; 
        Toast.makeText(context, info, Toast.LENGTH_LONG).show(); 
      } 
    } 

} 

E voi ragazzi non dimenticate di aggiungere l'autorizzazione in AndroidManifest di file:

<receiver android:name="com.varma.samples.detectcalls.receivers.OutgoingCallReceiver" > 
      <intent-filter> 
       <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 
      </intent-filter> 
     </receiver> 
     <receiver android:name="com.varma.samples.detectcalls.receivers.IncomingCallReceiver" > 
      <intent-filter> 
       <action android:name="android.intent.action.PHONE_STATE" /> 
      </intent-filter> 
     </receiver> 

    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> 
    <uses-permission android:name="android.permission.CALL_PHONE" /> 
    <uses-permission android:name="android.permission.CALL_PRIVILEGED" /> 
+0

Fate questo metodo richiede l'Android da radicare Posso scrivere questo in un normale telefono Android –

+0

Sì, è possibile .... –

6

Provare a utilizzare questi solution.Also riferimento this

public class OutgoingCallReceiver extends BroadcastReceiver { 

    public static final String ABORT_PHONE_NUMBER = "1231231234"; 

    private static final String OUTGOING_CALL_ACTION = "android.intent.action.NEW_OUTGOING_CALL"; 
    private static final String INTENT_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER"; 

    @Override 
    public void onReceive(final Context context, final Intent intent) { 
     Log.v(Constants.LOGTAG, "OutgoingCallReceiver onReceive"); 
     if (intent.getAction().equals(OutgoingCallReceiver.OUTGOING_CALL_ACTION)) { 
     Log.v(Constants.LOGTAG, "OutgoingCallReceiver NEW_OUTGOING_CALL received"); 

     // get phone number from bundle 
     String phoneNumber = intent.getExtras().getString(OutgoingCallReceiver.INTENT_PHONE_NUMBER); 
     if ((phoneNumber != null) && phoneNumber.equals(OutgoingCallReceiver.ABORT_PHONE_NUMBER)) { 
      Toast.makeText(context, "NEW_OUTGOING_CALL intercepted to number 123-123-1234 - aborting call", 
        Toast.LENGTH_LONG).show(); 
      this.abortBroadcast(); 
     } 
     } 
    } 
} 
+0

si può anche rifiutare la chiamata per qualsiasi numero predefinito anche dall'alto codice o rimuovere quelle linee di conoscere il numero di telefono –

Problemi correlati