android.telephony.PhoneStateListener Java Examples
The following examples show how to use
android.telephony.PhoneStateListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamService.java From example with Apache License 2.0 | 6 votes |
@Override public void onDestroy() { super.onDestroy(); Log.d("tag", "remove notification"); if (mediaPlayer != null) { if (mediaPlayer.isPlaying()) { mediaPlayer.stop(); } mediaPlayer.release(); } if (phoneStateListener != null) { telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE); } cancelNotification(); }
Example #2
Source File: TelephonyRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void notifyDataActivityForSubscriber(int subId, int state) { if (!checkNotifyPermission("notifyDataActivity()" )) { return; } int phoneId = SubscriptionManager.getPhoneId(subId); synchronized (mRecords) { if (validatePhoneId(phoneId)) { mDataActivity[phoneId] = state; for (Record r : mRecords) { // Notify by correct subId. if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_ACTIVITY) && idMatch(r.subId, subId, phoneId)) { try { r.callback.onDataActivity(state); } catch (RemoteException ex) { mRemoveList.add(r.binder); } } } } handleRemoveListLocked(); } }
Example #3
Source File: BackgroundUploader.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onCreate() { super.onCreate(); Log.v(TAG, "onCreate()"); try { queue = QueueManager.initQueue(this); // Try to process the upload queue. Will check credentials if necessary. processUploadQueue(); } catch (Exception e) { Log.e(TAG, "Exception creating background uploading service: " + e.toString()); e.printStackTrace(); } TelephonyManager telephony = (TelephonyManager) getSystemService( Application.TELEPHONY_SERVICE); if (telephony != null) { telephony.listen(new DataConnectionListener(), PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); } }
Example #4
Source File: CallOutActivity.java From commcare-android with Apache License 2.0 | 6 votes |
private void dispatchAction() { if (Intent.ACTION_CALL.equals(calloutAction)) { tManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); Intent call = new Intent(Intent.ACTION_CALL); call.setData(Uri.parse("tel:" + number)); if (call.resolveActivity(getPackageManager()) != null) { startActivityForResult(call, CALL_RESULT); } else { Toast.makeText(this, Localization.get("callout.failure.dialer"), Toast.LENGTH_SHORT).show(); finish(); } } else { Intent sms = new Intent(Intent.ACTION_SENDTO); sms.setData(Uri.parse("smsto:" + number)); if (sms.resolveActivity(getPackageManager()) != null) { startActivityForResult(sms, SMS_RESULT); } else { Toast.makeText(this, Localization.get("callout.failure.sms"), Toast.LENGTH_SHORT).show(); finish(); } } }
Example #5
Source File: TrafficMeterAbstract.java From GravityBox with Apache License 2.0 | 6 votes |
@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(); } }
Example #6
Source File: CellLocationController.java From cordova-plugin-advanced-geolocation with Apache License 2.0 | 6 votes |
/** * Full stop using brute force. Works with many Android versions. */ public void stopLocation(){ if(_phoneStateListener != null && _telephonyManager != null){ _telephonyManager.listen(_phoneStateListener, PhoneStateListener.LISTEN_NONE); } if(_signalStrengthListener != null && _telephonyManager != null){ _telephonyManager.listen(_signalStrengthListener, PhoneStateListener.LISTEN_NONE); } _signalStrengthListener = null; _phoneStateListener = 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"); }
Example #7
Source File: ServiceSinkhole.java From tracker-control-android with GNU General Public License v3.0 | 6 votes |
private void listenConnectivityChanges() { // Listen for connectivity updates Log.i(TAG, "Starting listening to connectivity changes"); IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); registeredConnectivityChanged = true; // Listen for phone state changes Log.i(TAG, "Starting listening to service state changes"); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (tm != null) { tm.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); phone_state = true; } }
Example #8
Source File: AudioStreamingService.java From DMAudioStreamer with Apache License 2.0 | 6 votes |
@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); }
Example #9
Source File: TelephonyRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void notifyUserMobileDataStateChangedForPhoneId(int phoneId, int subId, boolean state) { if (!checkNotifyPermission("notifyUserMobileDataStateChanged()")) { return; } if (VDBG) { log("notifyUserMobileDataStateChangedForSubscriberPhoneID: subId=" + phoneId + " state=" + state); } synchronized (mRecords) { if (validatePhoneId(phoneId)) { mMessageWaiting[phoneId] = state; for (Record r : mRecords) { if (r.matchPhoneStateListenerEvent( PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) && idMatch(r.subId, subId, phoneId)) { try { r.callback.onUserMobileDataStateChanged(state); } catch (RemoteException ex) { mRemoveList.add(r.binder); } } } } handleRemoveListLocked(); } }
Example #10
Source File: TelephonyRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void notifyPreciseDataConnectionFailed(String reason, String apnType, String apn, String failCause) { if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) { return; } synchronized (mRecords) { mPreciseDataConnectionState = new PreciseDataConnectionState( TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause); for (Record r : mRecords) { if (r.matchPhoneStateListenerEvent( PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) { try { r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState); } catch (RemoteException ex) { mRemoveList.add(r.binder); } } } handleRemoveListLocked(); } broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause); }
Example #11
Source File: TelephonyRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void notifyVoLteServiceStateChanged(VoLteServiceState lteState) { if (!checkNotifyPermission("notifyVoLteServiceStateChanged()")) { return; } synchronized (mRecords) { mVoLteServiceState = lteState; for (Record r : mRecords) { if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_VOLTE_STATE)) { try { r.callback.onVoLteServiceStateChanged( new VoLteServiceState(mVoLteServiceState)); } catch (RemoteException ex) { mRemoveList.add(r.binder); } } } handleRemoveListLocked(); } }
Example #12
Source File: MediaPlayerImpl.java From dcs-sdk-java with Apache License 2.0 | 6 votes |
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); }
Example #13
Source File: TelephonyRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void notifyOemHookRawEventForSubscriber(int subId, byte[] rawData) { if (!checkNotifyPermission("notifyOemHookRawEventForSubscriber")) { return; } synchronized (mRecords) { for (Record r : mRecords) { if (VDBG) { log("notifyOemHookRawEventForSubscriber: r=" + r + " subId=" + subId); } if ((r.matchPhoneStateListenerEvent( PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT)) && ((r.subId == subId) || (r.subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID))) { try { r.callback.onOemHookRawEvent(rawData); } catch (RemoteException ex) { mRemoveList.add(r.binder); } } } handleRemoveListLocked(); } }
Example #14
Source File: ServicePlayer.java From freemp with Apache License 2.0 | 6 votes |
@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(), RcvMediaControl.class.getName())); } if (android.os.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(); }
Example #15
Source File: MainActivity.java From Android-Example with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); //TelephonyManager object CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener(); telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); //Register our listener with TelephonyManager Bundle bundle = intent.getExtras(); String phoneNr= bundle.getString("incoming_number"); Log.v(TAG, "phoneNr: "+phoneNr); mContext=context; }
Example #16
Source File: CellTracker.java From AIMSICDL with GNU General Public License v3.0 | 5 votes |
public void stop() { if (isMonitoringCell()) { setCellMonitoring(false); } if (isTrackingCell()) { setCellTracking(false); } cancelNotification(); tm.listen(mCellSignalListener, PhoneStateListener.LISTEN_NONE); prefs.unregisterOnSharedPreferenceChangeListener(this); }
Example #17
Source File: RecorderService.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); //1.��ȡ�绰������ TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); //2.�����绰״̬ //arg0:�绰������ //arg1���绰��������������״̬�ָܶ࣬��ֻ�����绰״̬�ı� tm.listen(new MyListener(), PhoneStateListener.LISTEN_CALL_STATE); }
Example #18
Source File: MapFragment.java From AIMSICDL with GNU General Public License v3.0 | 5 votes |
@Override public void onDestroyView() { super.onDestroyView(); LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver); if (mCompassOverlay != null) { mCompassOverlay.disableCompass(); } if (mMyLocationOverlay != null) { mMyLocationOverlay.disableMyLocation(); } if(prefs != null) { prefs.unregisterOnSharedPreferenceChangeListener(this); } // Unbind from the service if (mBound) { getActivity().unbindService(mConnection); mBound = false; } TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver); }
Example #19
Source File: DeviceApi18.java From AIMSICDL with GNU General Public License v3.0 | 5 votes |
public static void startListening(TelephonyManager tm, PhoneStateListener listener) { tm.listen(listener, PhoneStateListener.LISTEN_CELL_INFO | PhoneStateListener.LISTEN_CELL_LOCATION | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS ); }
Example #20
Source File: MobileCommProcessor.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 监听电话的接听和结束事件 */ private void phoneCallListener() { //电话状态监听 TelephonyManager telManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); telManager.listen(new MobliePhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE); }
Example #21
Source File: AudioStreamingService.java From DMAudioStreamer with Apache License 2.0 | 5 votes |
@Override public void onCreate() { audioStreamingManager = AudioStreamingManager.getInstance(AudioStreamingService.this); audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); NotificationManager.getInstance().addObserver(this, NotificationManager.audioProgressDidChanged); NotificationManager.getInstance().addObserver(this, NotificationManager.setAnyPendingIntent); NotificationManager.getInstance().addObserver(this, NotificationManager.audioPlayStateChanged); try { phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { if (audioStreamingManager.isPlaying()) { audioStreamingManager.handlePauseRequest(); } } else if (state == TelephonyManager.CALL_STATE_IDLE) { } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) { } super.onCallStateChanged(state, incomingNumber); } }; TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mgr != null) { mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } } catch (Exception e) { Log.e("tmessages", e.toString()); } super.onCreate(); }
Example #22
Source File: TelephonyModule.java From react-native-telephony with MIT License | 5 votes |
@Override public Map<String, Object> getConstants() { final Map<String, Object> constants = new HashMap<>(); constants.put(LISTEN_CALL_FORWARDING_INDICATOR, PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR); constants.put(LISTEN_CALL_STATE, PhoneStateListener.LISTEN_CALL_STATE); constants.put(LISTEN_CELL_INFO, PhoneStateListener.LISTEN_CELL_INFO); constants.put(LISTEN_CELL_LOCATION, PhoneStateListener.LISTEN_CELL_LOCATION); constants.put(LISTEN_DATA_ACTIVITY, PhoneStateListener.LISTEN_DATA_ACTIVITY); constants.put(LISTEN_DATA_CONNECTION_STATE, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); constants.put(LISTEN_MESSAGE_WAITING_INDICATOR, PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR); constants.put(LISTEN_SERVICE_STATE, PhoneStateListener.LISTEN_SERVICE_STATE); constants.put(LISTEN_SIGNAL_STRENGTHS, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); constants.put("DATA_ACTIVITY_NONE", DATA_ACTIVITY_NONE); constants.put("DATA_ACTIVITY_IN", DATA_ACTIVITY_IN); constants.put("DATA_ACTIVITY_OUT", DATA_ACTIVITY_OUT); constants.put("DATA_ACTIVITY_INOUT", DATA_ACTIVITY_INOUT); constants.put("DATA_ACTIVITY_DORMANT", DATA_ACTIVITY_DORMANT); constants.put("DATA_DISCONNECTED", DATA_DISCONNECTED); constants.put("DATA_CONNECTING", DATA_CONNECTING); constants.put("DATA_CONNECTED", DATA_CONNECTED); constants.put("DATA_SUSPENDED", DATA_SUSPENDED); constants.put("CALL_STATE_IDLE", CALL_STATE_IDLE); constants.put("CALL_STATE_RINGING", CALL_STATE_RINGING); constants.put("CALL_STATE_OFFHOOK", CALL_STATE_OFFHOOK); return constants; }
Example #23
Source File: AnnouncementPeriodicTask.java From mytracks with Apache License 2.0 | 5 votes |
@Override public void shutdown() { listenToPhoneState(phoneStateListener, PhoneStateListener.LISTEN_NONE); if (tts != null) { tts.shutdown(); tts = null; } }
Example #24
Source File: ScreenOffEventReceiver.java From android-screen-off with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { TelephonyManager telephony = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); telephony.listen(new ScreenOffPhoneListener(context), PhoneStateListener.LISTEN_CALL_STATE); }
Example #25
Source File: CellBackendHelper.java From android_external_UnifiedNlpApi with Apache License 2.0 | 5 votes |
/** * Call this in {@link org.microg.nlp.api.LocationBackendService#onClose()}. */ @Override public synchronized void onClose() { super.onClose(); if (phoneStateListener != null) telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE); }
Example #26
Source File: NotificationListenerService.java From GoFIT_SDK_Android with Apache License 2.0 | 5 votes |
@Override public void onDestroy() { super.onDestroy(); mContext = null; ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)).listen(mPhoneReceiver, PhoneStateListener.LISTEN_NONE); mPhoneReceiver = null; AppContract.notificationServiceContext = null; }
Example #27
Source File: NotificationService.java From androidpn-client with Apache License 2.0 | 5 votes |
private void registerConnectivityReceiver() { Log.d(LOGTAG, "registerConnectivityReceiver()..."); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); IntentFilter filter = new IntentFilter(); // filter.addAction(android.net.wifi.WifiManager.NETWORK_STATE_CHANGED_ACTION); filter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityReceiver, filter); }
Example #28
Source File: PauseCallObserver.java From Kore with Apache License 2.0 | 5 votes |
public PauseCallObserver(Context context) { this.mContext = context; mHostManager = HostManager.getInstance(context); ((TelephonyManager)mContext .getSystemService(Context.TELEPHONY_SERVICE)) .listen(this, PhoneStateListener.LISTEN_CALL_STATE); }
Example #29
Source File: UCNetAnalysisManager.java From netanalysis-sdk-android with Apache License 2.0 | 5 votes |
private void startMonitorNetStatus() { if (mNetStatusReceiver != null) return; mNetStatusReceiver = new UNetStatusReceiver(); IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); intentFilter.addCategory(Intent.CATEGORY_DEFAULT); mContext.registerReceiver(mNetStatusReceiver, intentFilter); mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); }
Example #30
Source File: PhoneReceiver.java From talk-android with MIT License | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (!intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { TelephonyManager manager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE); manager.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE); } }