当前位置: 首页>>代码示例>>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;未经允许,请勿转载。