开发学院手机开发Android 开发 Android 开发总结之获取来电号码 阅读

Android 开发总结之获取来电号码

 2010-02-22 16:21:00 来源:WEB开发网   
核心提示:@Overridepublic void onReceive(Context context, Intent intent) {Log.i(TAG, "WE ARE INSIDE!!!!!!!!!!!");TelephonyManager telephony = (TelephonyManager)

@Override

public void onReceive(Context context, Intent intent) {

Log.i(TAG, "WE ARE INSIDE!!!!!!!!!!!");

TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();

telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

Bundle bundle = intent.getExtras();

String phoneNr= bundle.getString("incoming_number");

Log.i(TAG, "phoneNr: "+phoneNr);

}

}

public class CustomBroadcastReceiver extends BroadcastReceiver {

private static final String TAG = "CustomBroadcastReceiver";

@Override

public void onReceive(Context context, Intent intent) {

Log.i(TAG, "WE ARE INSIDE!!!!!!!!!!!");

TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();

telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

Bundle bundle = intent.getExtras();

String phoneNr= bundle.getString("incoming_number");

Log.i(TAG, "phoneNr: "+phoneNr);

}

}

Java代码

public class CustomPhoneStateListener extends PhoneStateListener {

private static final String TAG = "CustomPhoneStateListener";

@Override

public void onCallStateChanged(int state, String incomingNumber){

Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!");

Log.v(TAG, incomingNumber);

switch(state){

case TelephonyManager.CALL_STATE_RINGING:

Log.d(TAG, "RINGING");

break;

case TelephonyManager.CALL_STATE_IDLE:

Log.d(TAG, "IDLE");

break;

Tags:Android 开发 总结

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接