2012-06-25 5 views
0

Я хочу, чтобы заблокировать конкретный номер телефона, который находится в моей базе данныхКак заблокировать конкретные исходящие вызовы

я сделать сравнение между числом пользователь набранного, а число в памяти. Если они равны, я блокирую вызов.

Мой код:

public void onReceive(Context context, Intent intent) { 

    PlaceDataSQL placeDataSQL =new PlaceDataSQL(context); 
    ArrayList<String> getUsersPhoneNumbers= placeDataSQL.getUsersPhoneNumbers(); 
    //TODO 
    //=========== 
    //here I need to check the number 

    Bundle b = intent.getExtras(); 
    String incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); 
    //String outGoingNumber = b.getString(TelephonyManager.); 
    Boolean find=false; 
    try { 

     for(int i=0;i<getUsersPhoneNumbers.size();i++) 
     { 
      if(incommingNumber.equals(getUsersPhoneNumbers.get(i))) 
      { 
       find=true; 
       break; 
      } 
     } 

    } catch (Exception e) { 
     incommingNumber=""; 
    } 


// ======================================== 
//here the problem 
//========================================= 
    String phonenumber=b.getString(Intent.EXTRA_PHONE_NUMBER); 
    try { 

     for(int i=0;i<getUsersPhoneNumbers.size();i++) 
     { 
      if(phonenumber.equals(getUsersPhoneNumbers.get(i))) 
      { 
       find=true; 
       break; 
      } 
     } 
     if (!find) 
      return; 
    }catch (Exception e) { 
     phonenumber=""; 
    } 

    if (!find) 
     return; 


    /* examine the state of the phone that caused this receiver to fire off */ 
    String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); 
    if (phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING)) 
    { 

     logMe("Phone Ringing: the phone is ringing, scheduling creation call answer screen activity"); 
     Intent i = new Intent(context, CallAnswerIntentService.class); 
     i.putExtra("delay", 100L); 
     i.putExtra("number", incommingNumber); 
     context.startService(i); 
     logMe("Phone Ringing: started, time to go back to listening"); 


    } 

    if (phone_state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) 
    { 

     Intent i = new Intent(context,InCallScreenGuardService.class); 
     i.putExtra("delay", 100L); 
     i.putExtra("number", phonenumber); 
     logMe("Phone Offhook: starting screen guard service"); 
     context.startService(i); 

    } 

    if (phone_state.equals(TelephonyManager.EXTRA_STATE_IDLE)) 
    { 
     Intent i = new Intent(context,InCallScreenGuardService.class); 
     logMe("Phone Idle: stopping screen guard service"); 
     context.stopService(i); 

    } 

    return; 
} 

Проблема:

я могу получить входящие номера, но я не могу получить исходящие номера?

ответ

0

Для этого вам понадобится BroadcastReciever.

public class OutgoingCallReceiver extends BroadcastReceiver { 

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

     Toast.makeText(context, info, Toast.LENGTH_LONG).show(); 
    } 
} 
Смежные вопросы