本文整理汇总了Java中android.telephony.TelephonyManager.listen方法的典型用法代码示例。如果您正苦于以下问题:Java TelephonyManager.listen方法的具体用法?Java TelephonyManager.listen怎么用?Java TelephonyManager.listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.TelephonyManager
的用法示例。
在下文中一共展示了TelephonyManager.listen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPhoneListener
import android.telephony.TelephonyManager; //导入方法依赖的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);
}
}
示例2: initPhoneCallListener
import android.telephony.TelephonyManager; //导入方法依赖的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);
}
}
示例3: Afspiller
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* 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); }
}
示例4: onDestroy
import android.telephony.TelephonyManager; //导入方法依赖的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);
}
示例5: onCreate
import android.telephony.TelephonyManager; //导入方法依赖的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);
}
示例6: AudioHelper
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
public AudioHelper(Context context, PlayerEngine playerEngine, Class<? extends BroadcastReceiver> cls) {
this(context, null);
mPlayerEngine = playerEngine;
componentName = new ComponentName(context.getPackageName(), cls.getName());
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
phoneStateListener = new MobilePhoneStateListener();
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
示例7: run
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
@Override
public void run() {
Looper looper = initializeLooper();
ListenCallback callback = new ListenCallback(looper);
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(callback, PhoneStateListener.LISTEN_SERVICE_STATE);
Looper.loop();
telephonyManager.listen(callback, PhoneStateListener.LISTEN_NONE);
set(callback.isConnected());
}
示例8: onReceive
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
@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) {
super.onCallStateChanged(state, incomingNumber);
if (state == 1 && incomingNumber != null && incomingNumber.length() > 0) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceiveCall, PhoneFormat.stripExceptNumbers(incomingNumber));
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
示例9: initSystemServices
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
private void initSystemServices() {
TelephonyManager telephonyManager =
(TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_IDLE) startAudio();
else stopAudio();
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
示例10: onDestroyView
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
@Override
public void onDestroyView() {
super.onDestroyView();
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver);
if (mCompassOverlay != null) {
mCompassOverlay.disableCompass();
}
if (mMyLocationOverlay != null) {
mMyLocationOverlay.disableMyLocation();
}
if(prefs != null) {
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
// Unbind from the service
if (mBound) {
getActivity().unbindService(mConnection);
mBound = false;
}
TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mMessageReceiver);
}
示例11: onDestroy
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
@Override
protected void onDestroy() {
super.onDestroy();
prefs.unregisterOnSharedPreferenceChangeListener(this);
// Unbind from the service
if (mBound) {
unbindService(mConnection);
mBound = false;
}
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
}
示例12: init
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
@Override
public ControllerParent<PhoneShield> init(String tag) {
phoneListener = new PhoneCallStateListener();
phoneListener.setPhoneRingingEventHandler(phoneRingingEventHandler);
telephonyManager = (TelephonyManager) getApplication()
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
return super.init(tag);
}
示例13: callStateListener
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
/**
* Handle PhoneState changes
*/
private void callStateListener() {
// Get the telephony manager
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
//Starting listening for PhoneState changes
phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
//if at least one call exists or the phone is ringing
//pause the MediaPlayer
case TelephonyManager.CALL_STATE_OFFHOOK:
case TelephonyManager.CALL_STATE_RINGING:
if (mediaPlayer != null) {
pauseMedia();
ongoingCall = true;
}
break;
case TelephonyManager.CALL_STATE_IDLE:
// Phone idle. Start playing.
if (mediaPlayer != null) {
if (ongoingCall) {
ongoingCall = false;
resumeMedia();
}
}
break;
}
}
};
// Register the listener with the telephony manager
// Listen for changes to the device call state.
telephonyManager.listen(phoneStateListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
示例14: onResume
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
// Check if permissions were revoked
checkPermissions();
// Listen for preference changes
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
// Listen for interactive state changes
IntentFilter ifInteractive = new IntentFilter();
ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(interactiveStateReceiver, ifInteractive);
// Listen for connectivity updates
IntentFilter ifConnectivity = new IntentFilter();
ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(connectivityChangedReceiver, ifConnectivity);
if (Util.hasPhoneStatePermission(this)) {
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(phoneStateListener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE | PhoneStateListener.LISTEN_SERVICE_STATE);
phone_state = true;
}
}
示例15: attachTo
import android.telephony.TelephonyManager; //导入方法依赖的package包/类
public void attachTo(PieLayout container) {
mPieContainer = container;
mPieContainer.clearSlices();
mPieContainer.setSysinfoDisabled(mSysinfoDisabled);
mPieContainer.setLongpressDelay(mLongpressDelay);
if (DEBUG) {
log("Attaching to container: " + container);
}
mPieContainer.setOnSnapListener(this);
// construct navbar slice
int inner = mGbResources.getDimensionPixelSize(R.dimen.pie_navbar_radius);
int outer = inner + mGbResources.getDimensionPixelSize(R.dimen.pie_navbar_height);
mNavigationSlice = new PieSliceContainer(mPieContainer, PieSlice.IMPORTANT
| PieDrawable.DISPLAY_ALL);
mNavigationSlice.setGeometry(START_ANGLE, 180 - 2 * EMPTY_ANGLE, inner, outer);
setupNavigationItems();
mPieContainer.addSlice(mNavigationSlice);
// construct sysinfo slice
inner = mGbResources.getDimensionPixelSize(R.dimen.pie_sysinfo_radius);
outer = inner + mGbResources.getDimensionPixelSize(R.dimen.pie_sysinfo_height);
mSysInfo = new PieSysInfo(mContext, mGbContext, mPieContainer, this, PieDrawable.DISPLAY_NOT_AT_TOP);
mSysInfo.setGeometry(START_ANGLE, 180 - 2 * EMPTY_ANGLE, inner, outer);
mPieContainer.addSlice(mSysInfo);
// start listening for changes
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
mContext.registerReceiver(mBroadcastReceiver, intentFilter);
if (mHasTelephony) {
TelephonyManager telephonyManager =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
}
}