Java Code Examples for android.telephony.TelephonyManager#listen()
The following examples show how to use
android.telephony.TelephonyManager#listen() .
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: BackgroundExoAudioService.java From YouTube-In-Background with MIT License | 6 votes |
private void initPhoneCallListener() { PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == CALL_STATE_RINGING) { // Incoming call: Pause music playbackManager.handlePauseRequest(); } else if (state == CALL_STATE_IDLE) { // Not in call: Play music playbackManager.handlePlayRequest(); } else if (state == CALL_STATE_OFFHOOK) { // A call is dialing, active or on hold } super.onCallStateChanged(state, incomingNumber); } }; TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mgr == null) return; mgr.listen(phoneStateListener, LISTEN_CALL_STATE); }
Example 2
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 3
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 4
Source File: CallActivity.java From sealrtc-android with MIT License | 6 votes |
private void setCallIdel() { TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_RINGING: case TelephonyManager.CALL_STATE_OFFHOOK: // // RongRTCEngine.getInstance().muteMicrophone(true); break; case TelephonyManager.CALL_STATE_IDLE: // // RongRTCEngine.getInstance().muteMicrophone(false); break; } } }, PhoneStateListener.LISTEN_CALL_STATE); }
Example 5
Source File: PhoneStateMonitor.java From LibreTasks with Apache License 2.0 | 5 votes |
public void init() { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (tm == null) { Log.i(MONITOR_NAME, "Could not obtain TELEPHONY_SERVICE from the system."); return; } tm.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); tm.listen(phoneStateListener1, PhoneStateListener. LISTEN_SERVICE_STATE); }
Example 6
Source File: BasicApplication.java From myapplication with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); applicationInstance = this; requestQueue = Volley.newRequestQueue(getApplicationContext()); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mTelephonyManager.listen(new FindIndexMusicAty.MobliePhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE); }
Example 7
Source File: LockscreenActivity.java From Android-LockScreenSample-DisableHomeButtonKey with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); sLockscreenActivityContext = this; mMainHandler = new SendMassgeHandler(); // getWindow().setType(2004); // getWindow().addFlags(524288); // getWindow().addFlags(4194304); /// getWindow().setType(WindowManager.LayoutParams.FLAG_FULLSCREEN); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); } else { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); manager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); initLockScreenUi(); setLockGuard(); }
Example 8
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 9
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 10
Source File: AudioTrackPlayerImpl.java From dcs-sdk-java with Apache License 2.0 | 5 votes |
public AudioTrackPlayerImpl() { // init initAudioTrack(AUDIO_FORMAT_PCM8K, 1); // 读取音量和静音的数据 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<IMediaPlayerListener>()); // 来电监听 telephonyManager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); }
Example 11
Source File: AudioManager.java From QuranAndroid with GNU General Public License v3.0 | 5 votes |
/** * Listener to check incoming call */ private void initPhoneListener() { final PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { pauseMedia(); } else if (state == TelephonyManager.CALL_STATE_IDLE) { isInCall = false; if (isFirstStart == false) { if (Build.VERSION.SDK_INT >= 17.0) { bigNotification = true; largeMediaPlayer = LargeMediaPlayer.getInstance(context); } else { bigNotification = false; smallMediaPlayer = SmallMediaPlayer.getInstance(context); } resumeMedia(); } isFirstStart = false; } super.onCallStateChanged(state, incomingNumber); } }; telephoneManger = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephoneManger != null) { telephoneManger.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } }
Example 12
Source File: DownloadServiceLifecycleSupport.java From Audinaut with GNU General Public License v3.0 | 5 votes |
public void onDestroy() { serializeDownloadQueue(); eventLooper.quit(); downloadService.unregisterReceiver(ejectEventReceiver); downloadService.unregisterReceiver(intentReceiver); TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE); }
Example 13
Source File: PlayerService.java From BambooPlayer with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); mInitialized = false; mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mTelephonyManager.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); mAm = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int a = mAm.requestAudioFocus(focusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); }
Example 14
Source File: DataConnectionStats.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void startMonitoring() { TelephonyManager phone = (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE); phone.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_DATA_ACTIVITY); IntentFilter filter = new IntentFilter(); filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(ConnectivityManager.INET_CONDITION_ACTION); mContext.registerReceiver(this, filter); }
Example 15
Source File: PPureData.java From PHONK with GNU General Public License v3.0 | 5 votes |
private void initSystemServices() { TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_IDLE) startAudio(); else stopAudio(); } }, PhoneStateListener.LISTEN_CALL_STATE); }
Example 16
Source File: TelephonyServiceState.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Override public void run() { Looper looper = initializeLooper(); ListenCallback callback = new ListenCallback(looper); TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(callback, PhoneStateListener.LISTEN_SERVICE_STATE); Looper.loop(); telephonyManager.listen(callback, PhoneStateListener.LISTEN_NONE); set(callback.isConnected()); }
Example 17
Source File: PhoneReceiver.java From MainScreenShow with GNU General Public License v2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { this.context = context; if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { } else { // 非去电即来电 TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE); tm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); } }
Example 18
Source File: RetroWatchService.java From retrowatch with Apache License 2.0 | 4 votes |
/***************************************************** * * Private methods * ******************************************************/ private void initialize() { Logs.d(TAG, "# Service : initialize ---"); // Get content manager instance mContentManager = ContentManager.getInstance(mContext, this); // Get connection info instance mConnectionInfo = ConnectionInfo.getInstance(mContext); // Set notification broadcast receiver mReceiver = new NotificationReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(Constants.NOTIFICATION_LISTENER); registerReceiver(mReceiver,filter); // Set battery broadcast receiver IntentFilter iFilter = new IntentFilter(); iFilter.addAction(Intent.ACTION_BATTERY_CHANGED); registerReceiver(mBatteryInfoReceiver, iFilter); // Set SMS listener IntentFilter smsFilter = new IntentFilter(); smsFilter.addAction("android.provider.Telephony.SMS_RECEIVED"); registerReceiver(mSmsListener, smsFilter); // Set telephony listener TelephonyStateListener telephonyListener = new TelephonyStateListener(); TelephonyManager telephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); telephony.listen(telephonyListener, PhoneStateListener.LISTEN_SERVICE_STATE); telephony.listen(telephonyListener, PhoneStateListener.LISTEN_CALL_STATE); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); return; } if (!mBluetoothAdapter.isEnabled()) { // BT is not on, need to turn on manually. // Activity will do this. } else { if(mBtManager == null) { setupBT(); } } // Start service monitoring startServiceMonitoring(); }
Example 19
Source File: musicPlayer.java From Android-Music-Player with MIT License | 4 votes |
@Override public void onCreate() { TelephonyManager telephonyManager = (TelephonyManager)getSystemService(getBaseContext().TELEPHONY_SERVICE); PhoneStateListener callStateListener = new PhoneStateListener() { public void onCallStateChanged(int state, String incomingNumber) { if(state==TelephonyManager.CALL_STATE_RINGING){ //Toast.makeText(getApplicationContext(),"Phone Is Riging", Toast.LENGTH_LONG).show(); if(handler.mediaplayer.isPlaying()){ byCall = true; handler.mediaplayer.pause(); } } if(state==TelephonyManager.CALL_STATE_OFFHOOK){ //Toast.makeText(getApplicationContext(),"Phone is Currently in A call", Toast.LENGTH_LONG).show(); if(handler.mediaplayer.isPlaying()){ byCall = true; handler.mediaplayer.pause(); } } if(state==TelephonyManager.CALL_STATE_IDLE){ //Toast.makeText(getApplicationContext(),"phone is neither ringing nor in a call", Toast.LENGTH_LONG).show(); if(byCall){ byCall = false; handler.mediaplayer.start(); } } } }; telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE); mSettingsContentObserver = new SettingsContentObserver( new Handler() ); this.getContentResolver().registerContentObserver( android.provider.Settings.System.CONTENT_URI, true, mSettingsContentObserver ); THIS = this; handler = new musicHandler(this); super.onCreate(); //statusBar(); handler.mEvent.addEvent(new EventCall(new int[]{playerEvents.PLAYER_COMPLETE,playerEvents.SONG_CHANGED,playerEvents.PLAYING_FLIP}){ @Override public void onCall(final int eventId) { new Thread(){ @Override public void run() { showNotification(eventId); } }.start(); } }); showNotification(-1); }
Example 20
Source File: DeviceInfoActivty.java From PracticeDemo with Apache License 2.0 | 3 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_device_info_activty); mHandler.sendEmptyMessageDelayed(0, 0); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); //LISTEN_SIGNAL_STRENGTHS Listen for changes to the network signal strengths (cellular). mTelephonyManager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_SERVICE_STATE); }