private void setupSignalStrength() {
final TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final ImageView signalIcon = ((ImageView) statusBar.findViewById(R.id.signal_icon));
phoneListener = new PhoneStateListener() {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
if (manager.getNetworkOperator().equals("")) {
signalIcon.setVisibility(View.GONE);
} else {
signalIcon.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// See https://github.com/AlstonLin/TheLearningLock/issues/54
Integer imageRes = signalStrengthToIcon.get(signalStrength.getLevel());
if (imageRes != null) signalIcon.setImageResource(imageRes);
else signalIcon.setImageResource(signalStrengthToIcon.get(4));
} else {
// Just show the full icon
signalIcon.setImageResource(signalStrengthToIcon.get(4));
}
}
}
};
manager.listen(phoneListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
java类android.telephony.PhoneStateListener的实例源码
StatusBar.java 文件源码
项目:TheLearningLock
阅读 31
收藏 0
点赞 0
评论 0
MediaPlayerImpl.java 文件源码
项目:dcs-sdk-java
阅读 30
收藏 0
点赞 0
评论 0
public MediaPlayerImpl() {
mMediaPlayer = new MediaPlayer();
// set audio stream type
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setOnBufferingUpdateListener(bufferingUpdateListener);
mMediaPlayer.setOnErrorListener(errorListener);
mMediaPlayer.setOnPreparedListener(preparedListener);
mMediaPlayer.setOnCompletionListener(completionListener);
mMediaPlayer.setOnSeekCompleteListener(seekCompleteListener);
// 不同的音频源,此回调有的不回调!!!
// mMediaPlayer.setOnInfoListener(infoListener);
// 读取音量和静音的数据
currentVolume = (float) MediaPlayerPreferenceUtil.get(context,
KEY_SP_VOLUME, 0.8f);
isMute = (boolean) MediaPlayerPreferenceUtil.get(context,
KEY_SP_MUTE, false);
// LinkedList
mediaPlayerListeners = Collections.synchronizedList(new LinkedList<IMediaPlayer.IMediaPlayerListener>());
posHandler = new PosHandler(Looper.getMainLooper());
// 来电监听
telephonyManager = (TelephonyManager)
context.getSystemService(Service.TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
AudioService.java 文件源码
项目:Hello-Music-droid
阅读 41
收藏 0
点赞 0
评论 0
@Override
public void onDestroy() {
super.onDestroy();
if (mediaPlayer != null) {
stopMedia();
mediaPlayer.release();
}
removeAudioFocus();
//Disable the PhoneStateListener
if (phoneStateListener != null) {
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
}
removeNotification();
//unregister BroadcastReceivers
unregisterReceiver(becomingNoisyReceiver);
unregisterReceiver(playNewAudio);
//clear cached playlist
new PreferencesManager(getApplicationContext()).clearCachedAudioPlaylist();
}
AudioStreamingService.java 文件源码
项目:DMAudioStreamer
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void onDestroy() {
super.onDestroy();
if (remoteControlClient != null) {
RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
metadataEditor.clear();
metadataEditor.apply();
audioManager.unregisterRemoteControlClient(remoteControlClient);
}
try {
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
}
} catch (Exception e) {
Log.e("tmessages", e.toString());
}
NotificationManager.getInstance().removeObserver(this, NotificationManager.audioProgressDidChanged);
NotificationManager.getInstance().removeObserver(this, NotificationManager.audioPlayStateChanged);
}
ActivitySettings.java 文件源码
项目:MKAPP
阅读 21
收藏 0
点赞 0
评论 0
@Override
protected void onPause() {
super.onPause();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.unregisterOnSharedPreferenceChangeListener(this);
unregisterReceiver(interactiveStateReceiver);
unregisterReceiver(connectivityChangedReceiver);
if (phone_state) {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
phone_state = false;
}
}
RadioService.java 文件源码
项目:R-a-dio-Amazing-Android-App
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void onCreate() {
super.onCreate();
powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "KilimDankLock");
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "KilimDankWifiLock");
createMediaPlayer();
am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mTelephonyManager.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
// This stuff is for the broadcast receiver
IntentFilter filter = new IntentFilter();
// filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
registerReceiver(receiver, filter);
}
ReactNativeCallEventsModuleTest.java 文件源码
项目:react-native-call-events
阅读 17
收藏 0
点赞 0
评论 0
@Test
public void init_SetsUpListener() throws Exception {
ReactNativeCallEventsModule instance = getInstance();
//skip past the permissions check
PowerMockito.mockStatic(ContextCompat.class);
PowerMockito.when(ContextCompat.checkSelfPermission(mockActivity, Manifest.permission.READ_PHONE_STATE))
.thenReturn(PackageManager.PERMISSION_GRANTED);
PowerMockito.mockStatic(ActivityCompat.class);
PowerMockito.doNothing().when(ActivityCompat.class);
ActivityCompat.requestPermissions(mockActivity, new String[]{Manifest.permission.READ_PHONE_STATE}, 1);
instance.init(true, false);
verify(mockTelephonyManager);
mockTelephonyManager.listen(new CallStateListener(true, false, mockReactContext), PhoneStateListener.LISTEN_CALL_STATE);
}
PlayerService.java 文件源码
项目:IdealMedia
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void onDestroy() {
if (tm != null) {
tm.listen(telephone, PhoneStateListener.LISTEN_NONE);
tm = null;
}
if (myBroadcastReceiver != null) {
unregisterReceiver(myBroadcastReceiver);
}
if (mAudioManager != null) {
mAudioManager.unregisterMediaButtonEventReceiver(new ComponentName(getPackageName(), MediaControlReceiver.class.getName()));
}
if (Build.VERSION.SDK_INT >= 14 && remoteControlClient != null) {
unregisterRemoteControl();
}
// "free" the output device and all plugins
BASS.BASS_Free();
BASS.BASS_PluginFree(0);
// Stop foreground
stopForeground(true);
stopUpdateProgress();
super.onDestroy();
}
CellLocationController.java 文件源码
项目:localcloud_fe
阅读 25
收藏 0
点赞 0
评论 0
/**
* Full stop using brute force. Works with many Android versions.
*/
public void stopLocation(){
if(_phoneStateListener != null && _telephonyManager != null){
_telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_NONE);
_telephonyManager.listen(_signalStrengthListener, PhoneStateListener.LISTEN_NONE);
_phoneStateListener = null;
_signalStrengthListener = null;
_telephonyManager = null;
try {
Thread.currentThread().interrupt();
}
catch(SecurityException exc){
Log.e(TAG, exc.getMessage());
sendCallback(PluginResult.Status.ERROR,
JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.FAILED_THREAD_INTERRUPT()));
}
Log.d(TAG, "Stopping cell location listeners");
}
}
CellLocationController.java 文件源码
项目:localcloud_fe
阅读 24
收藏 0
点赞 0
评论 0
/**
* Full stop using brute force. Works with many Android versions.
*/
public void stopLocation(){
if(_phoneStateListener != null && _telephonyManager != null){
_telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_NONE);
_telephonyManager.listen(_signalStrengthListener, PhoneStateListener.LISTEN_NONE);
_phoneStateListener = null;
_signalStrengthListener = null;
_telephonyManager = null;
try {
Thread.currentThread().interrupt();
}
catch(SecurityException exc){
Log.e(TAG, exc.getMessage());
sendCallback(PluginResult.Status.ERROR,
JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.FAILED_THREAD_INTERRUPT()));
}
Log.d(TAG, "Stopping cell location listeners");
}
}
CellLocationController.java 文件源码
项目:localcloud_fe
阅读 27
收藏 0
点赞 0
评论 0
/**
* Full stop using brute force. Works with many Android versions.
*/
public void stopLocation(){
if(_phoneStateListener != null && _telephonyManager != null){
_telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_NONE);
_telephonyManager.listen(_signalStrengthListener, PhoneStateListener.LISTEN_NONE);
_phoneStateListener = null;
_signalStrengthListener = null;
_telephonyManager = null;
try {
Thread.currentThread().interrupt();
}
catch(SecurityException exc){
Log.e(TAG, exc.getMessage());
sendCallback(PluginResult.Status.ERROR,
JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.FAILED_THREAD_INTERRUPT()));
}
Log.d(TAG, "Stopping cell location listeners");
}
}
TelephonyRegistryStub.java 文件源码
项目:TPlayer
阅读 17
收藏 0
点赞 0
评论 0
@Override
protected void onBindMethods() {
super.onBindMethods();
addMethodProxy(new ReplaceCallingPkgMethodProxy("listen"));
addMethodProxy(new ReplaceSequencePkgMethodProxy("listenForSubscriber", 1) {
@Override
public boolean beforeCall(Object who, Method method, Object... args) {
if (android.os.Build.VERSION.SDK_INT >= 17) {
if (isFakeLocationEnable()) {
for (int i = args.length - 1; i > 0; i--) {
if (args[i] instanceof Integer) {
int events = (Integer) args[i];
events ^= PhoneStateListener.LISTEN_CELL_INFO;
events ^= PhoneStateListener.LISTEN_CELL_LOCATION;
args[i] = events;
break;
}
}
}
}
return super.beforeCall(who, method, args);
}
});
}
TrafficMeterAbstract.java 文件源码
项目:GravityBox
阅读 16
收藏 0
点赞 0
评论 0
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (!mAttached) {
mAttached = true;
if (DEBUG) log("attached to window");
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
filter.addAction(ModDownloadProvider.ACTION_DOWNLOAD_STATE_CHANGED);
getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
if (mPhone != null) {
mPhone.listen(mPhoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}
updateState();
}
}
MainActivity.java 文件源码
项目:android-fundamentals-phone-sms
阅读 19
收藏 0
点赞 0
评论 0
/**
* Creates the activity, sets the view, and checks if Telephony is enabled.
* Telephony enabled:
* Checks for phone permission.
* Sets the PhoneStateListener.
* Telephony not enabled: Disables the call button and shows the Retry button.
*
* @param savedInstanceState Instance state
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a telephony manager.
mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// Check to see if Telephony is enabled.
if (isTelephonyEnabled()) {
Log.d(TAG, getString(R.string.telephony_enabled));
// Check for phone permission.
checkForPhonePermission();
// Register the PhoneStateListener to monitor phone activity.
mListener = new MyPhoneCallListener();
mTelephonyManager.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
} else {
Toast.makeText(this,
R.string.telephony_not_enabled, Toast.LENGTH_LONG).show();
Log.d(TAG, getString(R.string.telephony_not_enabled));
// Disable the call button.
disableCallButton();
}
}
MainActivity.java 文件源码
项目:android-fundamentals-phone-sms
阅读 18
收藏 0
点赞 0
评论 0
/**
* Creates the activity, sets the view, and checks if Telephony is enabled.
* Telephony enabled:
* Checks for phone permission.
* Sets the PhoneStateListener.
* Telephony not enabled: Disables the call button and shows the Retry button.
*
* @param savedInstanceState Instance state
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a telephony manager.
mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// Check to see if Telephony is enabled.
if (isTelephonyEnabled()) {
Log.d(TAG, getString(R.string.telephony_enabled));
// Check for phone permission.
checkForPhonePermission();
// Register the PhoneStateListener to monitor phone activity.
mListener = new MyPhoneCallListener();
mTelephonyManager.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
} else {
Toast.makeText(this,
R.string.telephony_not_enabled, Toast.LENGTH_LONG).show();
Log.d(TAG, getString(R.string.telephony_not_enabled));
// Disable the call button.
disableCallButton();
}
}
PPureDataBackupNewer.java 文件源码
项目:phonk
阅读 17
收藏 0
点赞 0
评论 0
private void initSystemServices() {
TelephonyManager telephonyManager =
(TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
synchronized (lock) {
if (pdService == null) return;
if (state == TelephonyManager.CALL_STATE_IDLE) {
if (play && !pdService.isRunning()) {
startAudio();
}
} else {
if (pdService.isRunning()) {
stopAudio();
}
}
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
BackgroundAudioService.java 文件源码
项目:youtube_background_android
阅读 26
收藏 0
点赞 0
评论 0
private void initPhoneCallListener() {
PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
//Incoming call: Pause music
pauseVideo();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
//Not in call: Play music
Log.d(TAG, "onCallStateChanged: ");
resumeVideo();
} 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);
}
}
Afspiller.java 文件源码
项目:EsperantoRadio
阅读 15
收藏 0
点赞 0
评论 0
/**
* Forudsætter DRData er initialiseret
*/
public Afspiller() {
mediaPlayer = Wrapperfabrikering.opret();
sætMediaPlayerLytter(mediaPlayer, this.lytter);
wifilock = ((WifiManager) ApplicationSingleton.instans.getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "DR Radio");
wifilock.setReferenceCounted(false);
Opkaldshaandtering opkaldshåndtering = new Opkaldshaandtering(this);
try {
/* kræver
<uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="22" />
*/
TelephonyManager tm = (TelephonyManager) ApplicationSingleton.instans.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(opkaldshåndtering, PhoneStateListener.LISTEN_CALL_STATE);
} catch (Exception e) { Log.rapporterFejl(e); }
}
PlaybackService.java 文件源码
项目:Harmony-Music-Player
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void onDestroy() {
if (mMediaSession != null) {
mMediaSession.release();
}
unregisterReceiver(mHeadsetStateReceiver);
if (mTelephonyManager != null) {
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
saveSeekPos();
mAudioManager.abandonAudioFocus(mAudioFocusChangeListener);
mMediaPlayer.stop();
Intent i = new Intent(this, AudioEffectsReceiver.class);
i.setAction(AudioEffectsReceiver.ACTION_CLOSE_AUDIO_EFFECT_SESSION);
sendBroadcast(i);
mMediaPlayer.release();
super.onDestroy();
}
AppService.java 文件源码
项目:AudioBookPlayer
阅读 32
收藏 0
点赞 0
评论 0
@Override
public void onCreate() {
defaultIcon = BitmapFactory.decodeResource(getResources(), R.drawable.picture);
defaultIcon = Util.getScaledImage(defaultIcon, ICON_SIZE, ICON_SIZE, Util.getImageFactor(getResources()));
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
super.onCreate();
mp3Player.initialize();
restoreSettings();
mp3Player.getMediaPlayer().addChangeStateListener(this);
mp3Player.getAppSettings().addPropertyChangeListener(this);
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
musicIntentReceiver = new MusicIntentReceiver();
registerReceiver(musicIntentReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
}
AppService.java 文件源码
项目:AudioBookPlayer
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void onDestroy() {
super.onDestroy();
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if(mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
}
saveLastOpened(preferenceEditor);
releaseMediaPlayer();
audioManager.abandonAudioFocus(this);
if (preferenceEditor != null) {
preferenceEditor.commit();
preferenceEditor = null;
}
stopForeground(true);
}
AddressService.java 文件源码
项目:mobilesafe
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void onCreate() {
//��һ�ο��������Ժ�,����Ҫȥ������˾����ʾ
//�绰״̬�ļ���(��������ʱ��,��Ҫȥ������,�رյ�ʱ��绰״̬�Ͳ���Ҫ����)
//1,�绰�����߶���
mTM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
//2,�����绰״̬
mPhoneStateListener = new MyPhoneStateListener();
mTM.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
//��ȡ�������
mWM = (WindowManager) getSystemService(WINDOW_SERVICE);
mScreenHeight = mWM.getDefaultDisplay().getHeight();
mScreenWidth = mWM.getDefaultDisplay().getWidth();
//���������绰�Ĺ㲥��������(Ȩ��)
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_NEW_OUTGOING_CALL);
//�����㲥������
mInnerOutCallReceiver = new InnerOutCallReceiver();
registerReceiver(mInnerOutCallReceiver, intentFilter);
super.onCreate();
}
BlackNumberService.java 文件源码
项目:mobilesafe
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void onCreate() {
mDao = BlackNumberDao.getInstance(getApplicationContext());
//���ض���
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
intentFilter.setPriority(1000);
mInnerSmsReceiver = new InnerSmsReceiver();
registerReceiver(mInnerSmsReceiver, intentFilter);
//�����绰��״̬
//1,�绰�����߶���
mTM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
//2,�����绰״̬
mPhoneStateListener = new MyPhoneStateListener();
mTM.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
super.onCreate();
}
BlackNumberService.java 文件源码
项目:mobilesafe
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void onDestroy() {
//ע���㲥
if(mInnerSmsReceiver!=null){
unregisterReceiver(mInnerSmsReceiver);
}
//ע�����ݹ۲���
if(mContentObserver!=null){
getContentResolver().unregisterContentObserver(mContentObserver);
}
//ȡ���Ե绰״̬�ļ���
if(mPhoneStateListener!=null){
mTM.listen(mPhoneStateListener,PhoneStateListener.LISTEN_NONE);
}
super.onDestroy();
}
RecordingActivity.java 文件源码
项目:Android-Audio-Recorder
阅读 25
收藏 0
点赞 0
评论 0
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestory");
stopRecording();
if (receiver != null) {
unregisterReceiver(receiver);
receiver = null;
}
RecordingService.stopService(this);
if (pscl != null) {
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(pscl, PhoneStateListener.LISTEN_NONE);
pscl = null;
}
}
CellLocationController.java 文件源码
项目:cordova-plugin-advanced-geolocation
阅读 29
收藏 0
点赞 0
评论 0
/**
* Full stop using brute force. Works with many Android versions.
*/
public void stopLocation(){
if(_phoneStateListener != null && _telephonyManager != null){
_telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_NONE);
_telephonyManager.listen(_signalStrengthListener, PhoneStateListener.LISTEN_NONE);
_phoneStateListener = null;
_signalStrengthListener = null;
_telephonyManager = null;
try {
Thread.currentThread().interrupt();
}
catch(SecurityException exc){
Log.e(TAG, exc.getMessage());
sendCallback(PluginResult.Status.ERROR,
JSONHelper.errorJSON(CELLINFO_PROVIDER, ErrorMessages.FAILED_THREAD_INTERRUPT()));
}
Log.d(TAG, "Stopping cell location listeners");
}
}
BackgroundExoAudioService.java 文件源码
项目:YouTube-In-Background
阅读 20
收藏 0
点赞 0
评论 0
private void initPhoneCallListener()
{
PhoneStateListener phoneStateListener = new PhoneStateListener()
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
if (state == TelephonyManager.CALL_STATE_RINGING) {
//Incoming call: Pause music
mPlaybackManager.handlePauseRequest();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
//Not in call: Play music
mPlaybackManager.handlePlayRequest();
} 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);
}
}
MainService.java 文件源码
项目:android-QoS
阅读 20
收藏 0
点赞 0
评论 0
/**
* Add <code>phoneStateListener</code> as a listener to the many events related to the state
* of the phone.
*/
//MMCNetworkActiveListener wifilistener = new MMCNetworkActiveListener();
private void registerPhoneStateListener() {
int events = 0;
events = PhoneStateListener.LISTEN_CELL_LOCATION |
//PhoneStateListener.LISTEN_CELL_INFO |
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
PhoneStateListener.LISTEN_CALL_STATE |
PhoneStateListener.LISTEN_DATA_ACTIVITY |
PhoneStateListener.LISTEN_SERVICE_STATE;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, events);
}
ActivitySettings.java 文件源码
项目:NoRootFirewall-Custom
阅读 28
收藏 0
点赞 0
评论 0
@Override
protected void onPause() {
super.onPause();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.unregisterOnSharedPreferenceChangeListener(this);
unregisterReceiver(interactiveStateReceiver);
unregisterReceiver(connectivityChangedReceiver);
if (phone_state) {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);
phone_state = false;
}
}
RadioService.java 文件源码
项目:R-a-dio-Amazing-Android-App
阅读 26
收藏 0
点赞 0
评论 0
@Override
public void onCreate() {
super.onCreate();
powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "KilimDankLock");
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "KilimDankWifiLock");
createMediaPlayer();
am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mTelephonyManager.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
// This stuff is for the broadcast receiver
IntentFilter filter = new IntentFilter();
// filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
registerReceiver(receiver, filter);
}