List of usage examples for android.telephony PhoneStateListener LISTEN_CALL_STATE
int LISTEN_CALL_STATE
To view the source code for android.telephony PhoneStateListener LISTEN_CALL_STATE.
Click Source Link
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); }
From source file:com.neuron.fantecremote.PhoneIntentReciever.java
@Override public void onReceive(Context context, Intent intent) { MyPhoneStateListener phoneListener = new MyPhoneStateListener( context.getSharedPreferences("fantecremote", 0)); TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); }
From source file:ro.ui.pttdroid.Player.java
@Override public void onCreate() { playerThread = new PlayerThread(); playerThread.start();/* w w w. ja v a 2 s. com*/ telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); phoneCallListener = new PhoneCallListener(); telephonyManager.listen(phoneCallListener, PhoneStateListener.LISTEN_CALL_STATE); Intent intent = new Intent(this, Main.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); Notification notification = new NotificationCompat.Builder(this).setContentTitle(getText(R.string.app_name)) .setContentText(getText(R.string.app_running)).setSmallIcon(R.drawable.notif_icon) .setContentIntent(pendingIntent).build(); startForeground(1, notification); }
From source file:me.tassoevan.cordova.PhoneTrapPlugin.java
private boolean doOnCallAction(JSONArray args, CallbackContext callbackContext) { try {//from w ww . j a va 2 s. c om if (listener == null) { listener = new CallStateListener(); TelephonyManager TelephonyMgr = (TelephonyManager) cordova.getActivity() .getSystemService(Context.TELEPHONY_SERVICE); TelephonyMgr.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); } listener.callbackContext = callbackContext; return true; } catch (Exception e) { this.logError("Exception occurred: ".concat(e.getMessage())); callbackContext.error("Exception occurred: ".concat(e.getMessage())); return false; } }
From source file:com.example.android.phonecallingsample.MainActivity.java
/** * Creates the activity, sets the view, and checks if Telephony is enabled. * Telephony enabled:// w w w . j a va 2s. c om * 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(); } }
From source file:es.warp.desktop_droid.TelephonyEventService.java
@Override public void onCreate() { Toast.makeText(this, "My service created", Toast.LENGTH_LONG); Log.d("TelephonyEventService", "onCreate"); TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); manager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); }
From source file:org.easyaccess.phonedialer.CallStateService.java
@Override public void onCreate() { telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); callStateListener = new CallStateListener(); callState = telephonyManager.getCallState(); telephonyManager.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE); callState = telephonyManager.getCallState(); broadcaster = LocalBroadcastManager.getInstance(this); tts = new TextToSpeech(this, this); this.bReceiver = new BroadcastReceiver() { @Override//from w ww .ja va 2s. co m public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Utils.INCOMING_CALL)) { /** * Extentia : * As per the security guidelines third party apps can't receive/answer call programmatically * unless its a system app. So user must need to use default app to receive/answer call. * Hiding below piece of code to display default app to answer call. * * */ // cxt = context; // String number = intent.getStringExtra("message"); // callingDetails = new ContactManager(getBaseContext()) // .getNameFromNumber(number); // // play ringtone // // get custom ringtone // playRingtone(number); // // announce number // // Display Calling Activity in order to receive key events // Utils.callingDetails = callingDetails; // myIntent = new Intent(getBaseContext(), CallingScreen.class); // myIntent.putExtra("type", Utils.INCOMING); // myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // // new Handler().postDelayed(new Runnable() { // @Override // public void run() { // startActivity(myIntent); // } // }, 2000); } else if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) { // new outgoing call final String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); callingDetails = new ContactManager(getBaseContext()).getNameFromNumber(number); Utils.callingDetails = callingDetails; } } }; LocalBroadcastManager.getInstance(this).registerReceiver((this.bReceiver), new IntentFilter(Utils.INCOMING_CALL)); LocalBroadcastManager.getInstance(this).registerReceiver((this.bReceiver), new IntentFilter("android.intent.action.PHONE_STATE")); if (Accelerometer.isSupported(this)) { // Start Accelerometer Listening Accelerometer.startListening(this); } MediaButton_Receiver mediaReceiver = new MediaButton_Receiver(); IntentFilter filterVolume = new IntentFilter(Intent.ACTION_MEDIA_BUTTON); registerReceiver(mediaReceiver, filterVolume); SettingsContentObserver mSettingsContentObserver = new SettingsContentObserver(this, new Handler()); getApplicationContext().getContentResolver().registerContentObserver( android.provider.Settings.System.CONTENT_URI, true, mSettingsContentObserver); }
From source file:ru.piter.fm.activities.RadioActivity.java
private void initUI() { setContentView(R.layout.main);//from ww w . j a v a 2s .co m mPager = (ViewPager) findViewById(R.id.pager); mAdapter = new RadioAdapter(getSupportFragmentManager()); actionBar = getSupportActionBar(); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); getSupportActionBar().setDisplayShowTitleEnabled(true); actionBar.addTab(actionBar.newTab().setText("PITER FM").setTabListener(this)); actionBar.addTab(actionBar.newTab().setText("MOSKVA FM").setTabListener(this)); mAdapter.addFragment(new RadioFragment(RadioFactory.getRadio(RadioFactory.PITER_FM))); mAdapter.addFragment(new RadioFragment(RadioFactory.getRadio(RadioFactory.MOSKVA_FM))); mPager.setAdapter(mAdapter); mPager.setOnPageChangeListener(this); TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); tm.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); }
From source file:com.goftagram.telegram.messenger.MusicPlayerService.java
@Override public void onCreate() { audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged); try {/*from w w w. j ava 2 s .c om*/ phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { if (MediaController.getInstance() .isPlayingAudio(MediaController.getInstance().getPlayingMessageObject()) && !MediaController.getInstance().isAudioPaused()) { MediaController.getInstance() .pauseAudio(MediaController.getInstance().getPlayingMessageObject()); } } 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) { FileLog.e("tmessages", e); } super.onCreate(); }
From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java
@Override public void onCreate() { audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); NotificationManager.getInstance().addObserver(this, NotificationManager.audioProgressDidChanged); NotificationManager.getInstance().addObserver(this, NotificationManager.audioPlayStateChanged); try {//from w ww .j ava2 s . c o m phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { if (MediaController.getInstance() .isPlayingAudio(MediaController.getInstance().getPlayingSongDetail()) && !MediaController.getInstance().isAudioPaused()) { MediaController.getInstance() .pauseAudio(MediaController.getInstance().getPlayingSongDetail()); } } 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(); }