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


Java TelephonyManager.listen方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:fekracomputers,項目名稱:QuranAndroid,代碼行數:38,代碼來源:AudioManager.java

示例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);
    }
}
 
開發者ID:pawelpaszki,項目名稱:youtube_background_android,代碼行數:24,代碼來源:BackgroundAudioService.java

示例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); }
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:19,代碼來源:Afspiller.java

示例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);
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:21,代碼來源:AudioStreamingService.java

示例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);
    }
 
開發者ID:R-a-dio,項目名稱:R-a-dio-Amazing-Android-App,代碼行數:23,代碼來源:RadioService.java

示例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);
}
 
開發者ID:suifenge,項目名稱:MusicPlayerEngine,代碼行數:9,代碼來源:AudioHelper.java

示例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());
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:15,代碼來源:TelephonyServiceState.java

示例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);
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:14,代碼來源:CallReceiver.java

示例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);
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:12,代碼來源:PPureData.java

示例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);
}
 
開發者ID:5GSD,項目名稱:AIMSICDL,代碼行數:29,代碼來源:MapFragment.java

示例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);
}
 
開發者ID:5GSD,項目名稱:AIMSICDL,代碼行數:15,代碼來源:MapViewerOsmDroid.java

示例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);
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:11,代碼來源:PhoneShield.java

示例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);
}
 
開發者ID:CommonsLab,項目名稱:CommonsLab,代碼行數:38,代碼來源:MediaPlayerService.java

示例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;
    }
}
 
開發者ID:miankai,項目名稱:MKAPP,代碼行數:29,代碼來源:ActivitySettings.java

示例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);
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:41,代碼來源:PieController.java


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