android.telephony.TelephonyManager.getCallState()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中android.telephony.TelephonyManager.getCallState()方法的一些代码示例,展示了TelephonyManager.getCallState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TelephonyManager.getCallState()方法的具体详情如下:
包路径:android.telephony.TelephonyManager
类名称:TelephonyManager
方法名:getCallState

TelephonyManager.getCallState介绍

暂无

代码示例

代码示例来源:origin: square/assertj-android

public TelephonyManagerAssert hasCallState(@TelephonyManagerCallState int state) {
 isNotNull();
 int actualState = actual.getCallState();
 //noinspection ResourceType
 assertThat(actualState) //
   .overridingErrorMessage("Expected call state <%s> but was <%s>.", callStateToString(state),
     callStateToString(actualState)) //
   .isEqualTo(state);
 return this;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldGiveCallState() {
 PhoneStateListener listener = mock(PhoneStateListener.class);
 telephonyManager.listen(listener, LISTEN_CALL_STATE);
 shadowOf(telephonyManager).setCallState(CALL_STATE_RINGING, "911");
 assertEquals(CALL_STATE_RINGING, telephonyManager.getCallState());
 verify(listener).onCallStateChanged(CALL_STATE_RINGING, "911");
 shadowOf(telephonyManager).setCallState(CALL_STATE_OFFHOOK, "911");
 assertEquals(CALL_STATE_OFFHOOK, telephonyManager.getCallState());
 verify(listener).onCallStateChanged(CALL_STATE_OFFHOOK, null);
}

代码示例来源:origin: stackoverflow.com

TelephonyManager telMgr = (TelephonyManager)(this.getMainContext()
            .getSystemService(Context.TELEPHONY_SERVICE));
/* Making a call... */
if (telMgr.getCallState() != TelephonyManager.CALL_STATE_OFFHOOK) { /* Do your stuff */ }

代码示例来源:origin: stackoverflow.com

TelephonyManager mgr = getSystemService(Context.TELEPHONY_SERVICE);
int callState = mgr.getCallState();
if (callState != TelephonyManager.CALL_STATE_RINGING )
  break;

代码示例来源:origin: stackoverflow.com

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
int callState = tm.getCallState();

代码示例来源:origin: gdpancheng/LoonAndroid3

/**
 * 获取电话状态
 * 
 * @author gdpancheng@gmail.com 2013-10-22 下午1:16:37
 * @return String
 */
public static String getCallState() {
  switch (mTm.getCallState()) {
  case android.telephony.TelephonyManager.CALL_STATE_IDLE:
    return "电话状态[CallState]: 无活动";
  case android.telephony.TelephonyManager.CALL_STATE_OFFHOOK:
    return "电话状态[CallState]: 无活动";
  case android.telephony.TelephonyManager.CALL_STATE_RINGING:
    return "电话状态[CallState]: 无活动";
  default:
    return "电话状态[CallState]: 未知";
  }
}

代码示例来源:origin: stackoverflow.com

public class PhoneStateReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

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

  switch(telManager.getCallState()) {
  case TelephonyManager.CALL_STATE_IDLE:
   //do something
  }
}

代码示例来源:origin: stackoverflow.com

private boolean isUserInCall(Context context) {
  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE;
}

代码示例来源:origin: stackoverflow.com

public void onReceive(Context context, Intent intent)    
{
  TelephonyManager phoneManager =
    (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

  if(phoneManager.getCallState() == TelephonyManager.CALL_STATE_RINGING) 
  {
    string fromNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
    Log.i(TAG, "u have a call from a number " + fromNumber);
  }
}

代码示例来源:origin: stackoverflow.com

public class PhoneState extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {

    TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE); 

    switch (tm.getCallState()) {

      case TelephonyManager.CALL_STATE_RINGING:
          String phoneNr= intent.getStringExtra("incoming_number");
          Toast.makeText(context, phoneNr,Toast.LENGTH_LONG).show();
          break;
    } 
  }
}

代码示例来源:origin: stackoverflow.com

public class PhoneStateReceiver extends BroadcastReceiver {

private TelephonyManager manager;

@Override
public void onReceive(Context context, Intent intent) {
  if (manager == null) {
    manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  }
  String action = intent.getAction();
  System.out.println(action);
  System.out.println("current phone state:" + manager.getCallState());
}

代码示例来源:origin: stackoverflow.com

public void onReceive(Context context, Intent intent) {
 Log.v(Tag, "Start Listening Phone Call");
 TelephonyManager tm = (TelephonyManager) context
     .getSystemService(Context.TELEPHONY_SERVICE);
 switch (tm.getCallState()) {
 case TelephonyManager.CALL_STATE_IDLE:
   Log.v(Tag, "No call");
   break;
 case TelephonyManager.CALL_STATE_RINGING:
   Log.v(Tag, "A new call arrived and is ringing or waiting");
   Intent i = new Intent(context,MyActivity.class);
   i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   context.startActivity(i);
   break;
 }

代码示例来源:origin: stackoverflow.com

public class TestServiceReceiver extends BroadcastReceiver {

@Override
public void onReceive(final Context context, Intent intent) {
  TelephonyManager telephony = (TelephonyManager) context
  .getSystemService(Context.TELEPHONY_SERVICE);

  int state = telephony.getCallState();
  String incomingNumber =
    intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

  switch (state) {
  case TelephonyManager.CALL_STATE_IDLE:

    Log.d("@@@@@@@@@@@@@@@@@@@@@@@@@TestServiceReceiver", "IDLE");
    break;
  case TelephonyManager.CALL_STATE_OFFHOOK:

    Log.d("@@@@@@@@@@@@@@@@@@@@@@@@@TestServiceReceiver", "OFFHOOK");
    break;
  case TelephonyManager.CALL_STATE_RINGING:

    Log.d("@@@@@@@@@@@@@@@@@@@@@@@@TestServiceReceiver", "RINGING");
    break;
  }
}

代码示例来源:origin: stackoverflow.com

switch (tm.getCallState()) {

代码示例来源:origin: stackoverflow.com

@Override
public void onReceive(Context context, Intent intent) {
  TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  int callState = telephonyManager.getCallState();
  Bundle extras = intent.getExtras();

  if (extras == null) {
    return;
  }

  String incomingNumber = extras.getString("incoming_number");

  Log.d(TAG, "Receiving callStateChange: " + callState + " number: " + incomingNumber);

  switch (callState) {
    case TelephonyManager.CALL_STATE_RINGING :
      processIncomingNumber(context, incomingNumber);
      break;
    case TelephonyManager.CALL_STATE_IDLE :
      NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      nm.cancelAll();
      break;
  }
}

代码示例来源:origin: techstar-cloud/memorize-en

@Override
  public void onReceive(Context context, Intent intent) {
    if (null != context) {
      if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        Intent startLockscreenIntent = new Intent(mContext, LockScreenViewService.class);
        stopService(startLockscreenIntent);
        TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        boolean isPhoneIdle = tManager.getCallState() == TelephonyManager.CALL_STATE_IDLE;
        if (isPhoneIdle) {
          startLockscreenActivity();
        }
      }
    }
  }
};

代码示例来源:origin: stackoverflow.com

TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
switch (tm.getCallState()) {
case TelephonyManager.CALL_STATE_RINGING:  // incoming call
  incomingFlag = true;

代码示例来源:origin: stackoverflow.com

switch (tm.getCallState()) {
case TelephonyManager.CALL_STATE_RINGING:
    incomingFlag = true;//标识当前是来电

代码示例来源:origin: com.squareup.assertj/assertj-android

public TelephonyManagerAssert hasCallState(@TelephonyManagerCallState int state) {
 isNotNull();
 int actualState = actual.getCallState();
 //noinspection ResourceType
 assertThat(actualState) //
   .overridingErrorMessage("Expected call state <%s> but was <%s>.", callStateToString(state),
     callStateToString(actualState)) //
   .isEqualTo(state);
 return this;
}

代码示例来源:origin: stackoverflow.com

public void onReceive(Context context, Intent intent) {
  TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  if (telephony.getCallState() == 0) {

相关文章