Java Code Examples for android.telephony.PhoneStateListener

The following are top voted examples for showing how to use android.telephony.PhoneStateListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: TheLearningLock   File: StatusBar.java   Source Code and License 7 votes vote down vote up
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);
}
 
Example 2
Project: QuranAndroid   File: AudioManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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 3
Project: dcs-sdk-java   File: MediaPlayerImpl.java   Source Code and License 6 votes vote down vote up
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
Project: Hello-Music-droid   File: AudioService.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 5
Project: DMAudioStreamer   File: AudioStreamingService.java   Source Code and License 6 votes vote down vote up
@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 6
Project: MKAPP   File: ActivitySettings.java   Source Code and License 6 votes vote down vote up
@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;
    }
}
 
Example 7
Project: R-a-dio-Amazing-Android-App   File: RadioService.java   Source Code and License 6 votes vote down vote up
@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);
    }
 
Example 8
Project: react-native-call-events   File: ReactNativeCallEventsModuleTest.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 9
Project: IdealMedia   File: PlayerService.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 10
Project: localcloud_fe   File: CellLocationController.java   Source Code and License 6 votes vote down vote up
/**
 * 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");
    }
}
 
Example 11
Project: localcloud_fe   File: CellLocationController.java   Source Code and License 6 votes vote down vote up
/**
 * 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");
    }
}
 
Example 12
Project: localcloud_fe   File: CellLocationController.java   Source Code and License 6 votes vote down vote up
/**
 * 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");
    }
}
 
Example 13
Project: TPlayer   File: TelephonyRegistryStub.java   Source Code and License 6 votes vote down vote up
@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);
		}
	});
}
 
Example 14
Project: GravityBox   File: TrafficMeterAbstract.java   Source Code and License 6 votes vote down vote up
@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 15
Project: android-fundamentals-phone-sms   File: MainActivity.java   Source Code and License 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example 16
Project: android-fundamentals-phone-sms   File: MainActivity.java   Source Code and License 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example 17
Project: phonk   File: PPureDataBackupNewer.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 18
Project: youtube_background_android   File: BackgroundAudioService.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 19
Project: EsperantoRadio   File: Afspiller.java   Source Code and License 6 votes vote down vote up
/**
 * 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); }
}
 
Example 20
Project: Harmony-Music-Player   File: PlaybackService.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 21
Project: AudioBookPlayer   File: AppService.java   Source Code and License 6 votes vote down vote up
@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));	
	
}
 
Example 22
Project: AudioBookPlayer   File: AppService.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 23
Project: mobilesafe   File: AddressService.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 24
Project: mobilesafe   File: BlackNumberService.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 25
Project: mobilesafe   File: BlackNumberService.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 26
Project: Android-Audio-Recorder   File: RecordingActivity.java   Source Code and License 6 votes vote down vote up
@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;
    }
}
 
Example 27
Project: cordova-plugin-advanced-geolocation   File: CellLocationController.java   Source Code and License 6 votes vote down vote up
/**
 * 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");
    }
}
 
Example 28
Project: YouTube-In-Background   File: BackgroundExoAudioService.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 29
Project: android-QoS   File: MainService.java   Source Code and License 6 votes vote down vote up
/**
 * 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);

}
 
Example 30
Project: NoRootFirewall-Custom   File: ActivitySettings.java   Source Code and License 6 votes vote down vote up
@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;
    }
}
 
Example 31
Project: R-a-dio-Amazing-Android-App   File: RadioService.java   Source Code and License 6 votes vote down vote up
@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);
    }
 
Example 32
Project: things-notification   File: CallListener.java   Source Code and License 6 votes vote down vote up
@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) {
            Log.d(TAG, "Call received: "+incomingNumber);
            if (!incomingNumber.isEmpty()) {
                WritableNativeMap params = new WritableNativeMap();
                params.putString("app", "phone");
                params.putString("text", incomingNumber);
                NotificationModule.sendEvent("notificationReceived", params);
            }
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);
}
 
Example 33
Project: LockActivity   File: ScreenListenerService.java   Source Code and License 6 votes vote down vote up
private void listenTelephonyState() {
    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_IDLE:
                    //空闲
                    break;
                case TelephonyManager.CALL_STATE_RINGING:
                    //响铃
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    //挂机
                    break;
            }
        }
    },PhoneStateListener.LISTEN_CALL_STATE);
}
 
Example 34
Project: Android-IMSI-Catcher-Detector   File: CellTracker.java   Source Code and License 6 votes vote down vote up
/**
 * Start FemtoCell detection tracking (For CDMA Devices ONLY!)
 */
public void startTrackingFemto() {

    /* Check if it is a CDMA phone */
    if (device.getPhoneId() != TelephonyManager.PHONE_TYPE_CDMA) {
        Helpers.msgShort(context, context.getString(R.string.femtocell_only_on_cdma_devices));
        return;
    }

    trackingFemtocell = true;
    mPhoneStateListener = new PhoneStateListener() {
        public void onServiceStateChanged(ServiceState s) {
            log.debug(context.getString(R.string.service_state_changed));
            getServiceStateInfo(s);
        }
    };
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    setNotification();
}
 
Example 35
Project: Android-IMSI-Catcher-Detector   File: MapViewerOsmDroid.java   Source Code and License 6 votes vote down vote up
/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    log.info("Starting MapViewer");

    setUpMapIfNeeded();

    mDbHelper = new RealmHelper(this);
    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // Bind to LocalService
    Intent intent = new Intent(this, AimsicdService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION |
            PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}
 
Example 36
Project: mytracks   File: AnnouncementPeriodicTaskTest.java   Source Code and License 6 votes vote down vote up
public void testRun_ringWhileSpeaking() throws Exception {
  startTask(TextToSpeech.SUCCESS);

  expect(tts.isSpeaking()).andStubReturn(true);
  expect(tts.stop()).andReturn(TextToSpeech.SUCCESS);

  AndroidMock.replay(tts);

  // Update the state to ringing - this should stop the current announcement.
  PhoneStateListener phoneListener = phoneListenerCapture.getValue();
  phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);

  // Run the announcement - this should do nothing.
  task.run(null);

  AndroidMock.verify(mockTask, tts);
}
 
Example 37
Project: MobileGuard   File: BlacklistInterceptService.java   Source Code and License 6 votes vote down vote up
@Override
    public void onCreate() {
        super.onCreate();
//        System.out.println("BlacklistInterceptService onCreate");
        // register call listener
        telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

        // register sms receiver
        smsReceiver = new SmsReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Constant.ACTION_SMS_RECEIVED);
        // set max priority
        filter.setPriority(Integer.MAX_VALUE);
        // register
        registerReceiver(smsReceiver, filter);
    }
 
Example 38
Project: mobility-logger   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@Override
public void onResume(){
	super.onResume();

	// Wifi broadcast Receiver
	wifiReceiver = new WifiReceiver();
	registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
	wifiManager.startScan();
	
	// Location Manager and Listener
	if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minimumSeconds * 1000, minimumDistance, locationListener);

	// Telephony Manager and Listener
	wakeLock.acquire();
	telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION |
				PhoneStateListener.LISTEN_DATA_ACTIVITY | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
				PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
				| PhoneStateListener.LISTEN_CALL_STATE);
	// Phone and SIM information are static, i.e. not updated regularly but only here
	updatePhoneSimInfo();
}
 
Example 39
Project: QuranAndroid   File: AudioManager.java   Source Code and License 5 votes vote down vote up
/**
 * 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 40
Project: dcs-sdk-java   File: AudioTrackPlayerImpl.java   Source Code and License 5 votes vote down vote up
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);
}