Example usage for android.telephony TelephonyManager CALL_STATE_OFFHOOK

List of usage examples for android.telephony TelephonyManager CALL_STATE_OFFHOOK

Introduction

In this page you can find the example usage for android.telephony TelephonyManager CALL_STATE_OFFHOOK.

Prototype

int CALL_STATE_OFFHOOK

To view the source code for android.telephony TelephonyManager CALL_STATE_OFFHOOK.

Click Source Link

Document

Device call state: Off-hook.

Usage

From source file:com.neuron.fantecremote.PhoneIntentReciever.java

public void onCallStateChanged(int state, String incomingNumber) {
    switch (state) {
    case TelephonyManager.CALL_STATE_IDLE:
        //Log.d("DEBUG", "IDLE");
        break;//from  w ww  .j ava 2s.c  o  m
    case TelephonyManager.CALL_STATE_OFFHOOK:
        //Log.d("DEBUG", "OFFHOOK");
        break;
    case TelephonyManager.CALL_STATE_RINGING:
        //Log.d("DEBUG", "RINGING");
        String apiurl = Settings.GetApiUrl(prefs);
        if (apiurl != null && prefs.getBoolean("autopause", true)) {
            new SendCommandTask().execute(apiurl + "CMD_PAUSE");
        }
        break;
    }
}

From source file:com.goftagram.telegram.messenger.MusicPlayerService.java

@Override
public void onCreate() {
    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
    try {//from   ww w  . java 2 s  .  c  o m
        phoneStateListener = new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (state == TelephonyManager.CALL_STATE_RINGING) {
                    if (MediaController.getInstance()
                            .isPlayingAudio(MediaController.getInstance().getPlayingMessageObject())
                            && !MediaController.getInstance().isAudioPaused()) {
                        MediaController.getInstance()
                                .pauseAudio(MediaController.getInstance().getPlayingMessageObject());
                    }
                } else if (state == TelephonyManager.CALL_STATE_IDLE) {

                } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {

                }
                super.onCallStateChanged(state, incomingNumber);
            }
        };
        TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (mgr != null) {
            mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    super.onCreate();
}

From source file:co.codecrunch.musicplayerlite.manager.MusicPlayerService.java

@Override
public void onCreate() {
    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    NotificationManager.getInstance().addObserver(this, NotificationManager.audioProgressDidChanged);
    NotificationManager.getInstance().addObserver(this, NotificationManager.audioPlayStateChanged);
    try {// w ww .j a  v  a 2 s .  co  m
        phoneStateListener = new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (state == TelephonyManager.CALL_STATE_RINGING) {
                    if (MediaController.getInstance()
                            .isPlayingAudio(MediaController.getInstance().getPlayingSongDetail())
                            && !MediaController.getInstance().isAudioPaused()) {
                        MediaController.getInstance()
                                .pauseAudio(MediaController.getInstance().getPlayingSongDetail());
                    }
                } else if (state == TelephonyManager.CALL_STATE_IDLE) {

                } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {

                }
                super.onCallStateChanged(state, incomingNumber);
            }
        };
        TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (mgr != null) {
            mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
        }
    } catch (Exception e) {
        Log.e("tmessages", e.toString());
    }
    super.onCreate();
}

From source file:com.smedic.tubtub.BackgroundAudioService.java

private void initPhoneCallListener() {
    PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override/*  w  w w. j  a  v  a2 s  .c o  m*/
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                pauseVideo();
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                resumeVideo();
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
            default:
                break;
            }

            super.onCallStateChanged(state, incomingNumber);
        }
    };

    TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (mgr != null) {
        mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    }
}

From source file:com.nbplus.vbroadlauncher.BroadcastPushReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null) {
        return;/*w w w.j av a 2s .c  o m*/
    }
    Intent pi;

    String action = intent.getAction();
    if (PushConstants.ACTION_PUSH_STATUS_CHANGED.equals(action)) {
        LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
    } else if (PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(action)) {
        Log.d(TAG,
                "Receive.. broadcast ACTION_PUSH_MESSAGE_RECEIVED from push service. re-direct to activity!!!");
        //TODO: iot  ?.
        //            int i = 0;
        //            if (i == 0) {
        //                return;
        //            }
        PushMessageData data = null;
        try {
            data = (PushMessageData) intent.getParcelableExtra(PushConstants.EXTRA_PUSH_MESSAGE_DATA);
            if (data == null || StringUtils.isEmptyString(data.getPayload())) {
                Log.d(TAG, "empty push message string !!");
                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        PushPayloadData payloadData = null;
        try {
            Gson gson = new GsonBuilder().create();
            payloadData = gson.fromJson(data.getPayload(), new TypeToken<PushPayloadData>() {
            }.getType());
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (payloadData == null) {
            Log.d(TAG, "empty push message data !!");
            return;
        }

        String type = payloadData.getServiceType();
        Log.d(TAG, "HANDLER_MESSAGE_PUSH_MESAGE_RECEIVED received type = " + type + ", messageId = "
                + payloadData.getMessageId());
        payloadData.setAlertMessage(data.getAlert());
        switch (type) {
        // 
        case Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST:
        case Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST:
        case Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST:
            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            int callState = telephonyManager.getCallState();

            boolean isOutdoor = LauncherSettings.getInstance(context).isOutdoorMode();
            playNotificationAlarm(context, R.string.notification_broadcast_push);
            if (isOutdoor || callState == TelephonyManager.CALL_STATE_OFFHOOK) { // ? ? ?.
                Log.d(TAG, "Broadcast notification.. isOutdoor mode... ");
                pi = new Intent();
                pi.setAction(action);
                pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, intent.getIntExtra(
                        PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED));
                pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
                LocalBroadcastManager.getInstance(context).sendBroadcast(pi);

                return;
            }

            if (Constants.OPEN_BETA_PHONE) {
                String activePackageName = PackageUtils.getActivePackage(context);
                if (activePackageName != null && !StringUtils.isEmptyString(activePackageName)) {
                    if (Constants.VBROAD_SEND_APP_PACKAGE.equals(activePackageName)) {
                        Log.d(TAG, Constants.VBROAD_SEND_APP_PACKAGE + " is top running application....");
                        pi = new Intent();
                        pi.setAction(action);
                        pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE,
                                intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE,
                                        PushConstants.PUSH_STATUS_VALUE_DISCONNECTED));
                        pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
                        LocalBroadcastManager.getInstance(context).sendBroadcast(pi);

                        return;
                    }
                }
            }

            // ?? ?. ?  Domain url ??  .
            if (PackageUtils.isActivePackage(context, Constants.GOOGLE_CHROME_PACKAGE_NAME)) {
                Log.d(TAG, "chrome browser is active....");
                // get the last visited URL from the Browser.BOOKMARKS_URI database
                String url = "";
                Uri chromeUri = Uri.parse("content://com.android.chrome.browser/bookmarks");
                Cursor cur = context.getContentResolver().query(chromeUri/*Browser.BOOKMARKS_URI*/,
                        new String[] { Browser.BookmarkColumns.URL }, null, null,
                        Browser.BookmarkColumns.DATE + " DESC");
                if (cur != null && cur.getCount() > 0) {
                    cur.moveToFirst();
                    url = cur.getString(cur.getColumnIndex(Browser.BookmarkColumns.URL));
                    cur.close();
                } else {
                    if (cur != null) {
                        cur.close();
                    }
                }

                Log.d(TAG, "Last activated url = " + url);
                if (!StringUtils.isEmptyString(url) && (url.startsWith(Constants.VBROAD_HTTP_DOMAIN)
                        || url.startsWith(Constants.VBROAD_HTTPS_DOMAIN))) {
                    Log.w(TAG, ">> Village broadcast is running... do not show!!!!");
                    pi = new Intent();
                    pi.setAction(action);
                    pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE,
                            intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE,
                                    PushConstants.PUSH_STATUS_VALUE_DISCONNECTED));
                    pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
                    LocalBroadcastManager.getInstance(context).sendBroadcast(pi);
                    return;
                }
            }

            // android version check.
            if (Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(type)
                    || Constants.PUSH_PAYLOAD_TYPE_NORMAL_BROADCAST.equals(type)) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                    Log.d(TAG, ">> This device version code = " + Build.VERSION.SDK_INT
                            + ", not supported version !!");
                    Toast.makeText(context, R.string.notification_broadcast_not_support, Toast.LENGTH_SHORT);
                    pi = new Intent();
                    pi.setAction(action);
                    pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE,
                            intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE,
                                    PushConstants.PUSH_STATUS_VALUE_DISCONNECTED));
                    pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
                    LocalBroadcastManager.getInstance(context).sendBroadcast(pi);
                    break;
                }
            }
            /*boolean useServiceChatHead = false;
                    
            if (useServiceChatHead) {
                i = new Intent(context, RealtimeBroadcastProxyActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setAction(action);
                i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
                context.startActivity(i);
            } else*/

            String playingType = LauncherSettings.getInstance(context).getCurrentPlayingBroadcastType();

            if (StringUtils.isEmptyString(playingType)
                    || !Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(playingType)) {
                // ??? ... ? . ??? 
                pi = new Intent(context, RealtimeBroadcastActivity.class);
                pi.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                pi.setAction(action);
                pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
                pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, System.currentTimeMillis());

                Log.d(TAG, "1. sendBroadcast() >> ACTION_PUSH_MESSAGE_RECEIVED : idx = "
                        + pi.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1));
                // ? ms  ? ?? ? ?   ?  ????
                // broadcast ? .
                //  ?? ?? ??.
                //LocalBroadcastManager.getInstance(context).sendBroadcast(pi);

                try {
                    //Thread.sleep(30);
                    context.startActivity(pi);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                // ?? ? ??...  ? ?..  ? .
                if (Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(playingType)
                        && Constants.PUSH_PAYLOAD_TYPE_REALTIME_BROADCAST.equals(type)) {
                    pi = new Intent(context, RealtimeBroadcastActivity.class);
                    pi.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    pi.setAction(action);
                    pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
                    pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, System.currentTimeMillis());

                    Log.d(TAG, "2. sendBroadcast() >> ACTION_PUSH_MESSAGE_RECEIVED : idx = "
                            + pi.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1));
                    // ? ms  ? ?? ? ?   ?  ????
                    // broadcast ? .
                    //  ?? ?? ??.
                    //LocalBroadcastManager.getInstance(context).sendBroadcast(pi);
                    try {
                        //Thread.sleep(30);
                        context.startActivity(pi);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    // ? ? ? ??.
                    Log.d(TAG, "? ? ? ??.");
                    Toast.makeText(context, payloadData.getAlertMessage(), Toast.LENGTH_SHORT).show();
                }
            }
            break;
        // 
        case Constants.PUSH_PAYLOAD_TYPE_EMERGENCY_CALL:
            break;
        // 
        case Constants.PUSH_PAYLOAD_TYPE_INHABITANTS_POLL:
            // ?
        case Constants.PUSH_PAYLOAD_TYPE_COOPERATIVE_BUYING:
            int strId = Constants.PUSH_PAYLOAD_TYPE_INHABITANTS_POLL.equals(payloadData.getServiceType())
                    ? R.string.notification_inhabitant_push
                    : R.string.notification_cooperative_buying_push;
            playNotificationAlarm(context, strId);

            pi = new Intent();
            pi.setAction(action);
            pi.putExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, intent.getIntExtra(
                    PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED));
            pi.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, payloadData);
            Log.d(TAG, "3. sendBroadcast() >> ACTION_PUSH_MESSAGE_RECEIVED : idx = " + 0);
            LocalBroadcastManager.getInstance(context).sendBroadcast(pi);
            break;
        // IOT DEVICE ( )
        case Constants.PUSH_PAYLOAD_TYPE_IOT_DEVICE_CONTROL:
            Log.d(TAG, "startService >> ACTION_SEND_IOT_COMMAND");
            IoTInterface.getInstance().controlDevice(payloadData.getIotControlDeviceId(),
                    payloadData.getMessage());
            break;
        // PUSH_PAYLOAD_TYPE_PUSH_NOTIFICATION
        case Constants.PUSH_PAYLOAD_TYPE_PUSH_NOTIFICATION:
            // ?...
            //                    pi = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(payloadData.getMessage()));
            //                    showNotification(context, Constants.SYSTEM_ADMIN_NOTIFICATION_ID, PackageUtils.getApplicationName(context), payloadData.getAlertMessage(), null, pi);

            // bigText 
            showNotification(context, Constants.SYSTEM_ADMIN_NOTIFICATION_ID,
                    PackageUtils.getApplicationName(context), payloadData.getAlertMessage(),
                    PackageUtils.getApplicationName(context), payloadData.getMessage(), null, null, null);
            break;
        // IOT DEVICE ( )
        case Constants.PUSH_PAYLOAD_TYPE_FIND_PASSWORD:
            pi = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(payloadData.getMessage()));
            showNotification(context, Constants.PW_FIND_NOTIFICATION_ID,
                    PackageUtils.getApplicationName(context), payloadData.getAlertMessage(), null, pi);
            break;

        default:
            Log.d(TAG, "Unknown push payload type !!!");
            break;
        }
    }
}

From source file:com.pandoroid.PandoraRadioService.java

@Override
public void onCreate() {
    m_paused = false;//  w  ww  .ja  va2s .  c  om
    m_pandora_remote = new PandoraRadio();
    image_downloader = new ImageDownloader();
    m_stations = new ArrayList<Station>();

    connectivity_manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    m_prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    // Register the listener with the telephony manager
    telephonyManager.listen(new PhoneStateListener() {
        boolean pausedForRing = false;

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {

            case TelephonyManager.CALL_STATE_IDLE:
                if (pausedForRing && m_song_playback != null) {
                    if (m_prefs.getBoolean("behave_resumeOnHangup", true)) {
                        if (m_song_playback != null && !m_paused) {
                            m_song_playback.play();
                        }
                    }
                }

                pausedForRing = false;
                break;

            case TelephonyManager.CALL_STATE_OFFHOOK:
            case TelephonyManager.CALL_STATE_RINGING:
                if (m_song_playback != null) {
                    m_song_playback.pause();
                }

                pausedForRing = true;
                break;
            }
        }
    }, PhoneStateListener.LISTEN_CALL_STATE);

    m_music_intent_receiver = new MusicIntentReceiver();
    this.registerReceiver(m_music_intent_receiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
}

From source file:org.chirpradio.mobile.PlaybackService.java

private void setupTelephonyHooks() {
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

    phoneStateListener = new PhoneStateListener() {

        @Override//  www  .  j  a  v a2s . c om
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_OFFHOOK:
            case TelephonyManager.CALL_STATE_RINGING:
                if (isPlaying) {
                    Debug.log(this, "call began, stopping...");
                    stop();
                    isInCall = true;
                }
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                if (isInCall) {
                    isInCall = false;
                    Debug.log(this, "call ended; resuming...");
                    start();
                }
                break;
            }
        }
    };

    telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

private void printScreenAndCallState(String calledFrom) {
    boolean isScreenOn = powerManager.isScreenOn();

    if (!isScreenOn) {
        LOG.debug(calledFrom + ": Screen is off");
    } else {/*from   w ww.j  av  a  2 s  . c  o  m*/
        LOG.debug(calledFrom + ": Screen is on");
    }

    int phoneState = telephonyManager.getCallState();

    if (phoneState == TelephonyManager.CALL_STATE_RINGING
            || phoneState == TelephonyManager.CALL_STATE_OFFHOOK) {
        LOG.debug(calledFrom + ": Detected call activity");
    } else {
        LOG.debug(calledFrom + ": No active call.");
    }
}

From source file:leoisasmendi.android.com.suricatepodcast.services.MediaPlayerService.java

private void callStateListener() {
    // Get the telephony manager
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    //Starting listening for PhoneState changes
    phoneStateListener = new PhoneStateListener() {
        @Override//from w  w w.j  av  a2s  . c om
        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);
}

From source file:org.mariotaku.harmony.MusicPlaybackService.java

/**
 * Starts playback of a previously opened file.
 *//*www  .  j  a v  a  2  s  .co m*/
public void play() {
    final TrackInfo track = getTrackInfo();
    if (track == null)
        return;

    if (mTelephonyManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK)
        return;

    mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    mAudioManager.registerMediaButtonEventReceiver(
            new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));

    mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    if (mPlayer.isInitialized()) {
        // if we are at the end of the song, go to the next song first
        long duration = mPlayer.getDuration();
        if (mRepeatMode != REPEAT_MODE_CURRENT && duration > 2000 && mPlayer.getPosition() >= duration - 2000) {
            next(true);
        }

        mPlayer.start();

        // make sure we fade in, in case a previous fadein was stopped
        // because
        // of another focus loss
        mMediaplayerHandler.removeMessages(FADEDOWN);
        mMediaplayerHandler.sendEmptyMessage(FADEUP);

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        final NotificationCompat.Style style = new NotificationCompat.BigPictureStyle();
        builder.setSmallIcon(R.drawable.ic_stat_playback);
        builder.setContentTitle(track.title);
        if (!TrackInfo.isUnknownArtist(track)) {
            builder.setContentText(track.artist);
        } else if (!TrackInfo.isUnknownAlbum(track)) {
            builder.setContentText(track.album);
        } else {
            builder.setContentText(getString(R.string.unknown_artist));
        }
        final AlbumInfo album = AlbumInfo.getAlbumInfo(this, track);
        builder.setLargeIcon(getAlbumArtForNotification(album != null ? album.album_art : null));
        builder.setStyle(style);
        builder.setOngoing(true);
        builder.setOnlyAlertOnce(true);
        builder.setWhen(0);
        builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(INTENT_PLAYBACK_VIEWER), 0));

        startForeground(ID_NOTIFICATION_PLAYBACK, builder.getNotification());

        if (!mIsSupposedToBePlaying) {
            mIsSupposedToBePlaying = true;
            notifyChange(BROADCAST_PLAY_STATE_CHANGED);
        }

    } else if (mPlayListLen <= 0) {
        // This is mostly so that if you press 'play' on a bluetooth headset
        // without every having played anything before, it will still play
        // something.
        setShuffleMode(SHUFFLE_MODE_ALL);
    }
}