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

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

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

TelephonyManager.listen介绍

暂无

代码示例

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

TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr != null) {
  mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
}

代码示例来源:origin: pili-engineering/PLDroidPlayer

private void stopTelephonyListener() {
    if (mTelephonyManager != null && mPhoneStateListener != null) {
      mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
      mTelephonyManager = null;
      mPhoneStateListener = null;
    }
  }
}

代码示例来源:origin: oasisfeng/condom

@Override public void listen(final PhoneStateListener listener, final int events) {
  if ((events & UNSUPPORTED_LISTEN_EVENTS) != 0) {
    if (BuildConfig.DEBUG) throw new UnsupportedOperationException("One of the event type is not supported due to permission READ_PHONE_STATE required: " + events);
    super.listen(listener, events & ~ UNSUPPORTED_LISTEN_EVENTS);
  } else super.listen(listener, events);
}

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

public class ServiceReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(final Context context, Intent intent) {
    TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(new PhoneStateListener(){
      @Override
      public void onCallStateChanged(int state, String incomingNumber) {
        super.onCallStateChanged(state, incomingNumber);
        System.out.println("incomingNumber : "+incomingNumber);
      }
    },PhoneStateListener.LISTEN_CALL_STATE);
  }
}

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

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
public class PhoneCallReceiver extends BroadcastReceiver {  

@Override
public void onReceive(Context context, Intent intent) { 
  TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  PhoneCallStateListener customPhoneListener = new PhoneCallStateListener(context);
  telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);


}}

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

EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

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

PhoneStateListener phoneStateListener = new PhoneStateListener() {
  @Override
  public void onCallStateChanged(int state, String incomingNumber) {
    if (state == TelephonyManager.CALL_STATE_RINGING) {
      //Incoming call: Pause music
    } else if(state == TelephonyManager.CALL_STATE_IDLE) {
      //Not in call: Play music
    } else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
      //A call is dialing, active or on hold
    }
    super.onCallStateChanged(state, incomingNumber);
  }
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr != null) {
  mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

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

StateListener phoneStateListener = new StateListener();
TelephonyManager telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

代码示例来源:origin: pili-engineering/PLDroidPlayer

mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
} catch (Exception e) {
  e.printStackTrace();

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

@Test
public void testListenInit() {
 PhoneStateListener listener = mock(PhoneStateListener.class);
 telephonyManager.listen(listener, LISTEN_CALL_STATE | LISTEN_CELL_INFO | LISTEN_CELL_LOCATION);
 verify(listener).onCallStateChanged(CALL_STATE_IDLE, null);
 verify(listener).onCellLocationChanged(null);
 if (VERSION.SDK_INT >= JELLY_BEAN_MR1) {
  verify(listener).onCellInfoChanged(Collections.emptyList());
 }
}

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

@Test
@Config(minSdk = JELLY_BEAN_MR1)
public void shouldGiveAllCellInfo() {
 PhoneStateListener listener = mock(PhoneStateListener.class);
 telephonyManager.listen(listener, LISTEN_CELL_INFO);
 List<CellInfo> allCellInfo = Collections.singletonList(mock(CellInfo.class));
 shadowOf(telephonyManager).setAllCellInfo(allCellInfo);
 assertEquals(allCellInfo, telephonyManager.getAllCellInfo());
 verify(listener).onCellInfoChanged(allCellInfo);
}

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

@Test
 @Config(minSdk = P)
 public void shouldGiveSignalStrength() {
  PhoneStateListener listener = mock(PhoneStateListener.class);
  telephonyManager.listen(listener, LISTEN_SIGNAL_STRENGTHS);
  SignalStrength ss = Shadow.newInstanceOf(SignalStrength.class);

  shadowOf(telephonyManager).setSignalStrength(ss);

  verify(listener).onSignalStrengthsChanged(ss);
 }
}

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

@Test
public void shouldGiveCellLocation() {
 PhoneStateListener listener = mock(PhoneStateListener.class);
 telephonyManager.listen(listener, LISTEN_CELL_LOCATION);
 CellLocation mockCellLocation = mock(CellLocation.class);
 shadowOf(telephonyManager).setCellLocation(mockCellLocation);
 assertEquals(mockCellLocation, telephonyManager.getCellLocation());
 verify(listener).onCellLocationChanged(mockCellLocation);
}

代码示例来源: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 telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

telephonyManager.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR |
PhoneStateListener.LISTEN_CALL_STATE |
PhoneStateListener.LISTEN_CELL_LOCATION |
PhoneStateListener.LISTEN_DATA_ACTIVITY |
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR |
PhoneStateListener.LISTEN_SERVICE_STATE |
PhoneStateListener.LISTEN_SIGNAL_STRENGTH);

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

// Be careful by calling getActualDefaultRingtoneUri in CallListener, it could return null, better way to save it in OnCreate
 mOldUri = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE);
 TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
 mTelephonyMgr.listen(new MyCallListener(), PhoneStateListener.LISTEN_CALL_STATE);

代码示例来源:origin: Trumeet/MiPushFramework

@Override public void listen(final PhoneStateListener listener, final int events) {
  if ((events & UNSUPPORTED_LISTEN_EVENTS) != 0) {
    if (BuildConfig.DEBUG) throw new UnsupportedOperationException("One of the event type is not supported due to permission READ_PHONE_STATE required: " + events);
    super.listen(listener, events & ~ UNSUPPORTED_LISTEN_EVENTS);
  } else super.listen(listener, events);
}

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

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
 AndroidPhoneStateListener phoneStateListener = new AndroidPhoneStateListener(text);
 telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);

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

public class CallReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    MyPhoneStateListener phoneListener = new MyPhoneStateListener(context);
    TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
  }

}

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

PhoneCallListener phoneListener = new PhoneCallListener();
 TelephonyManager telephonyManager = (TelephonyManager) this
     .getSystemService(Context.TELEPHONY_SERVICE);
 telephonyManager.listen(phoneListener,
     PhoneStateListener.LISTEN_CALL_STATE);

相关文章