电话状态的监听:
/*** * 继承PhoneStateListener类,我们可以重新其内部的各种监听方法 然后通过手机状态改变时,系统自动触发这些方法来实现我们想要的功能 */ class MyPhoneStateListener extends PhoneStateListener { @Override public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE: Log.v(tag, "空闲状态 "); break; case TelephonyManager.CALL_STATE_RINGING: Log.v(tag, "手机铃声响了,来电号码:" + incomingNumber); break; case TelephonyManager.CALL_STATE_OFFHOOK: Log.v(tag, "通话状态 "); break; default: break; } super.onCallStateChanged(state, incomingNumber); } }
// 发送短信 smsManager = SmsManager.getDefault(); PendingIntent pIntent = PendingIntent.getBroadcast( ShopDealActivity.this, 0, new Intent(), 0); smsManager.sendTextMessage("10086", null, msg_string, pIntent, null); Toast.makeText(context, "短信已发送", Toast.LENGTH_SHORT) .show();
原文地址:http://blog.csdn.net/pengkv/article/details/38795965