如何识别来电和Android的呼出 [英] how to identify incoming call and outgoing call in android

查看:221
本文介绍了如何识别来电和Android的呼出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让来电和Android的呼出单独的事件。 其实我试图制定来电打开一个应用程序,如果数量存在于数据库和它的工作确定。但如果我从设备(呼出),如果来电号码是存在于数据库中仍然是打开我的应用程序。 我想限制打开我的呼出应用程序。

我的清单包含我收到来电是这样的:

 <接收机器人:名称=。IncomingCallReceiver>
    <意向滤光器>
        <作用机器人:名称=android.intent.action.PHONE_STATE/>
    &所述; /意图滤光器>
< /接收器>
 

IncomingCallReceiver:

  MyPhoneStateListener phoneListener =新MyPhoneStateListener(上下文);
TelephonyManager电话=(TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
 

MyPhoneStateListener:

 公共无效onCallStateChanged(INT状态,串incomingNumber){
      开关(州){
          案例TelephonyManager.CALL_STATE_IDLE:
              Log.d(调试,IDLE);
          打破;
          案例TelephonyManager.CALL_STATE_OFFHOOK:
              Log.d(调试,摘机);
              意图I =新的意图(背景下,MyMainActivity.class);
              i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(ⅰ);
          打破;
          案例TelephonyManager.CALL_STATE_RINGING:
              Log.d(调试,振铃);
          打破;
    }
}
 

谁能帮助我区分呼入呼出,所以我会处理这个事件。

在此先感谢。

解决方案
  

我想限制打开我的应用程序上呼出。

案例TelephonyManager.CALL_STATE_OFFHOOK:检查previous状态是 CALL_STATE_RINGING CALL_STATE_IDLE (例如,通过设置不同的标志,在两种情况下)。
在后一种情况下继续开你的应用程序,其他什么也不做

how to get the events of incoming call and outgoing call in android separately. Actually i was trying to develop an application that open on incoming call if number is exist in database and it work OK. but if i call from the device(outgoing call) and if number is exist in database still it open my application. i want to restrict to open my application on outgoing call.

my manifest contain i receive incoming call like this:

<receiver android:name=".IncomingCallReceiver" >
    <intent-filter >             
        <action android:name="android.intent.action.PHONE_STATE" />             
    </intent-filter>
</receiver>

IncomingCallReceiver:

MyPhoneStateListener phoneListener=new MyPhoneStateListener(context);
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);

MyPhoneStateListener:

public void onCallStateChanged(int state,String incomingNumber){
      switch(state) {
          case TelephonyManager.CALL_STATE_IDLE:
              Log.d("DEBUG", "IDLE");
          break;
          case TelephonyManager.CALL_STATE_OFFHOOK:
              Log.d("DEBUG", "OFFHOOK");                        
              Intent i = new Intent(context, MyMainActivity.class);
              i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(i);
          break;
          case TelephonyManager.CALL_STATE_RINGING:
              Log.d("DEBUG", "RINGING");
          break;
    }
}

can anyone help me to differentiate outgoing call from incoming call so i'll handle this events.

Thanks in advance.

解决方案

i want to restrict to open my application on outgoing call.

on case TelephonyManager.CALL_STATE_OFFHOOK: check if the previous state was CALL_STATE_RINGING or CALL_STATE_IDLE (for example by settings a different flag in both cases).
In the latter case proceed with opening your application, else do nothing

这篇关于如何识别来电和Android的呼出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆