當前位置: 首頁>>代碼示例>>Java>>正文


Java PhoneStateListener類代碼示例

本文整理匯總了Java中android.telephony.PhoneStateListener的典型用法代碼示例。如果您正苦於以下問題:Java PhoneStateListener類的具體用法?Java PhoneStateListener怎麽用?Java PhoneStateListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PhoneStateListener類屬於android.telephony包,在下文中一共展示了PhoneStateListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupSignalStrength

import android.telephony.PhoneStateListener; //導入依賴的package包/類
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);
}
 
開發者ID:AlstonLin,項目名稱:TheLearningLock,代碼行數:25,代碼來源:StatusBar.java

示例2: initPhoneListener

import android.telephony.PhoneStateListener; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:fekracomputers,項目名稱:QuranAndroid,代碼行數:38,代碼來源:AudioManager.java

示例3: MediaPlayerImpl

import android.telephony.PhoneStateListener; //導入依賴的package包/類
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);
}
 
開發者ID:dueros,項目名稱:dcs-sdk-java,代碼行數:27,代碼來源:MediaPlayerImpl.java

示例4: onDestroy

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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();
}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:23,代碼來源:AudioService.java

示例5: onDestroy

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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);
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:21,代碼來源:AudioStreamingService.java

示例6: onPause

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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;
    }
}
 
開發者ID:miankai,項目名稱:MKAPP,代碼行數:17,代碼來源:ActivitySettings.java

示例7: onCreate

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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);
    }
 
開發者ID:R-a-dio,項目名稱:R-a-dio-Amazing-Android-App,代碼行數:23,代碼來源:RadioService.java

示例8: init_SetsUpListener

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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);
}
 
開發者ID:HS2-SOLUTIONS,項目名稱:react-native-call-events,代碼行數:19,代碼來源:ReactNativeCallEventsModuleTest.java

示例9: onDestroy

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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();
}
 
開發者ID:dmllr,項目名稱:IdealMedia,代碼行數:26,代碼來源:PlayerService.java

示例10: stopLocation

import android.telephony.PhoneStateListener; //導入依賴的package包/類
/**
 * 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");
    }
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:25,代碼來源:CellLocationController.java

示例11: onBindMethods

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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);
		}
	});
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:25,代碼來源:TelephonyRegistryStub.java

示例12: onAttachedToWindow

import android.telephony.PhoneStateListener; //導入依賴的package包/類
@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();
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:19,代碼來源:TrafficMeterAbstract.java

示例13: onCreate

import android.telephony.PhoneStateListener; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:google-developer-training,項目名稱:android-fundamentals-phone-sms,代碼行數:32,代碼來源:MainActivity.java

示例14: initSystemServices

import android.telephony.PhoneStateListener; //導入依賴的package包/類
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);
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:22,代碼來源:PPureDataBackupNewer.java

示例15: initPhoneCallListener

import android.telephony.PhoneStateListener; //導入依賴的package包/類
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);
    }
}
 
開發者ID:pawelpaszki,項目名稱:youtube_background_android,代碼行數:24,代碼來源:BackgroundAudioService.java


注:本文中的android.telephony.PhoneStateListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。