Java 类android.telephony.PhoneStateListener 实例源码

项目:TheLearningLock    文件:StatusBar.java   
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);
}
项目:dcs-sdk-java    文件:MediaPlayerImpl.java   
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);
}
项目:Hello-Music-droid    文件:AudioService.java   
@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();
}
项目:DMAudioStreamer    文件:AudioStreamingService.java   
@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);
}
项目:MKAPP    文件:ActivitySettings.java   
@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;
    }
}
项目:R-a-dio-Amazing-Android-App    文件:RadioService.java   
@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);
    }
项目:react-native-call-events    文件:ReactNativeCallEventsModuleTest.java   
@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);
}
项目:IdealMedia    文件:PlayerService.java   
@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();
}
项目:localcloud_fe    文件:CellLocationController.java   
/**
 * 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");
    }
}
项目:localcloud_fe    文件:CellLocationController.java   
/**
 * 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");
    }
}
项目:localcloud_fe    文件:CellLocationController.java   
/**
 * 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");
    }
}
项目:TPlayer    文件:TelephonyRegistryStub.java   
@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);
        }
    });
}
项目:GravityBox    文件:TrafficMeterAbstract.java   
@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();
    }
}
项目:android-fundamentals-phone-sms    文件:MainActivity.java   
/**
 * 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();
    }
}
项目:android-fundamentals-phone-sms    文件:MainActivity.java   
/**
 * 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();
    }
}
项目:phonk    文件:PPureDataBackupNewer.java   
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);
}
项目:youtube_background_android    文件:BackgroundAudioService.java   
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);
    }
}
项目:EsperantoRadio    文件:Afspiller.java   
/**
 * 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); }
}
项目:Harmony-Music-Player    文件:PlaybackService.java   
@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();
}
项目:AudioBookPlayer    文件:AppService.java   
@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));    

}
项目:AudioBookPlayer    文件:AppService.java   
@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);
}
项目:mobilesafe    文件:AddressService.java   
@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();
}
项目:mobilesafe    文件:BlackNumberService.java   
@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();
}
项目:mobilesafe    文件:BlackNumberService.java   
@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();
}
项目:Android-Audio-Recorder    文件:RecordingActivity.java   
@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;
    }
}
项目:cordova-plugin-advanced-geolocation    文件:CellLocationController.java   
/**
 * 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");
    }
}
项目:YouTube-In-Background    文件:BackgroundExoAudioService.java   
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);
    }
}
项目:android-QoS    文件:MainService.java   
/**
 * 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);

}
项目:NoRootFirewall-Custom    文件:ActivitySettings.java   
@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;
    }
}
项目:R-a-dio-Amazing-Android-App    文件:RadioService.java   
@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);
    }
项目:things-notification    文件:CallListener.java   
@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);
}
项目:LockActivity    文件:ScreenListenerService.java   
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);
}
项目:Android-IMSI-Catcher-Detector    文件:CellTracker.java   
/**
 * 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();
}
项目:Android-IMSI-Catcher-Detector    文件:MapViewerOsmDroid.java   
/**
 * 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);
}
项目:mytracks    文件:AnnouncementPeriodicTaskTest.java   
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);
}
项目:MobileGuard    文件:BlacklistInterceptService.java   
@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);
    }
项目:mobility-logger    文件:MainActivity.java   
@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();
}
项目:QuranAndroid    文件:AudioManager.java   
/**
 * 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);
    }
}
项目:QuranAndroid    文件:AudioManager.java   
/**
 * 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);
    }
}
项目:dcs-sdk-java    文件:AudioTrackPlayerImpl.java   
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);
}