Android挂断、接听电话(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-01 14:14 点击:次
package lab.sodino.phonecall; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.telephony.TelephonyManager; import android.widget.Toast; /** *@author Sodino Email:sodinoopen@hotmail<br/> *@version 2011-2-6 下午10:38:55 */ public class PhoneListener extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); LogOut.out(this, "ord:" + isOrderedBroadcast() + " act:" + action); Toast toast = Toast.makeText(context, "", Toast.LENGTH_SHORT); if (action.equals("android.intent.action.NEW_OUTGOING_CALL")) { toast.setText("Outgoing"); } else { toast.setText("InComing"); TelephonyManager tm = (TelephonyManager) context .getSystemService(Service.TELEPHONY_SERVICE); boolean incomingFlag = false; String incoming_number = ""; switch (tm.getCallState()) { case TelephonyManager.CALL_STATE_RINGING: incomingFlag = true;// 标识当前是来电 incoming_number = intent.getStringExtra("incoming_number"); LogOut.out(this, "RINGING :" + incoming_number); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Intent tmpI = new Intent(context, ShowAct.class); tmpI.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(tmpI); break; case TelephonyManager.CALL_STATE_OFFHOOK: if (incomingFlag) { LogOut.out(this, "incoming ACCEPT :" + incoming_number); } break; case TelephonyManager.CALL_STATE_IDLE: if (incomingFlag) { LogOut.out(this, "incoming IDLE"); } break; } } toast.show(); } }
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>