Example usage for android.content ComponentName ComponentName

List of usage examples for android.content ComponentName ComponentName

Introduction

In this page you can find the example usage for android.content ComponentName ComponentName.

Prototype

private ComponentName(String pkg, Parcel in) 

Source Link

Usage

From source file:com.av.remusic.service.MediaService.java

public void play(boolean createNewNextTrack) {
    int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);

    if (D)//from   ww  w.  j  a v  a2 s.c om
        Log.d(TAG, "Starting playback: audio focus request status = " + status);

    if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        return;
    }

    final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
    intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
    intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(intent);

    mAudioManager.registerMediaButtonEventReceiver(
            new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        mSession.setActive(true);
    if (createNewNextTrack) {
        setNextTrack();
    } else {
        setNextTrack(mNextPlayPos);
    }
    if (mPlayer.isTrackPrepared()) {
        final long duration = mPlayer.duration();
        if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) {
            gotoNext(true);
        }
    }
    mPlayer.start();
    mPlayerHandler.removeMessages(FADEDOWN);
    mPlayerHandler.sendEmptyMessage(FADEUP);
    setIsSupposedToBePlaying(true, true);
    cancelShutdown();
    updateNotification();
    notifyChange(META_CHANGED);
}

From source file:com.cyanogenmod.eleven.MusicPlaybackService.java

/**
 * Resumes or starts playback.// w  ww . ja  v a 2  s .co m
 *
 * @param createNewNextTrack True if you want to figure out the next track, false
 *                           if you want to re-use the existing next track (used for going back)
 */
public void play(boolean createNewNextTrack) {
    int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);

    if (D)
        Log.d(TAG, "Starting playback: audio focus request status = " + status);

    if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        return;
    }

    final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
    intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
    intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
    sendBroadcast(intent);

    mAudioManager.registerMediaButtonEventReceiver(
            new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));
    mSession.setActive(true);

    if (createNewNextTrack) {
        setNextTrack();
    } else {
        setNextTrack(mNextPlayPos);
    }

    if (mPlayer.isInitialized()) {
        final long duration = mPlayer.duration();
        if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) {
            gotoNext(true);
        }

        mPlayer.start();
        mPlayerHandler.removeMessages(FADEDOWN);
        mPlayerHandler.sendEmptyMessage(FADEUP);

        setIsSupposedToBePlaying(true, true);

        cancelShutdown();
        updateNotification();
    } else if (mPlaylist.size() <= 0) {
        setShuffleMode(SHUFFLE_AUTO);
    }
}

From source file:com.android.soma.Launcher.java

protected ComponentName getWallpaperPickerComponent() {
    return new ComponentName(getPackageName(), WallpaperPickerActivity.class.getName());
}

From source file:com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.java

@SuppressLint("InlinedApi")
private void setUpRemoteControl(final MediaInfo info) {
    if (!isFeatureEnabled(BaseCastManager.FEATURE_LOCKSCREEN)) {
        return;//from   w w w  .  java  2  s . com
    }
    LOGD(TAG, "setUpRemoteControl() was called");
    mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

    mMediaEventReceiver = new ComponentName(mContext, VideoIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaEventReceiver);

    if (mRemoteControlClientCompat == null) {
        Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        intent.setComponent(mMediaButtonReceiverComponent);
        mRemoteControlClientCompat = new RemoteControlClientCompat(
                PendingIntent.getBroadcast(mContext, 0, intent, 0));
        RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat);
    }
    mRemoteControlClientCompat.addToMediaRouter(mMediaRouter);
    mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);
    if (info == null) {
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
        return;
    } else {
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }

    // Update the remote control's image
    updateLockScreenImage(info);

    // update the remote control's metadata
    updateLockScreenMetadata();
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

private void startKioskMode(String[] lockTaskArray) {
    // start locked activity
    Intent launchIntent = new Intent(getActivity(), KioskModeActivity.class);
    launchIntent.putExtra(KioskModeActivity.LOCKED_APP_PACKAGE_LIST, lockTaskArray);
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mPackageManager.setComponentEnabledSetting(
            new ComponentName(mPackageName, KioskModeActivity.class.getName()),
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    startActivity(launchIntent);/* w w  w  .j  ava  2s.  c om*/
    getActivity().finish();
}

From source file:com.adityarathi.muo.services.AudioPlaybackService.java

/**
 * (non-Javadoc)/*w  w  w .j  a va2 s .c  o  m*/
 * @see Service#onDestroy()
 */
@Override
public void onDestroy() {

    //Notify the UI that the service is about to stop.
    mApp.broadcastUpdateUICommand(new String[] { Common.SERVICE_STOPPING }, new String[] { "" });

    //Fire a broadcast message to the widget(s) to update them.
    //updateWidgets();

    //Send service stop event to GAnalytics.

    //Save the last track's info within the current queue.
    try {
        mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION",
                getCurrentMediaPlayer().getCurrentPosition());
    } catch (Exception e) {
        e.printStackTrace();
        mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION", 0);
    }

    //If the current song is repeating a specific range, reset the repeat option.
    if (getRepeatMode() == Common.REPEAT_SONG) {
        setRepeatMode(Common.REPEAT_OFF);
    }

    mFadeInVolume = 0.0f;
    mFadeOutVolume = 1.0f;

    //Unregister the headset plug receiver and RemoteControlClient.
    try {
        RemoteControlHelper.unregisterRemoteControlClient(mAudioManager, mRemoteControlClientCompat);
        unregisterReceiver(mHeadsetPlugReceiver);
    } catch (Exception e) {
        //Just null out the receiver if it hasn't been registered yet.
        mHeadsetPlugReceiver = null;
    }

    //Remove the notification.
    NotificationManager notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
    notificationManager.cancel(mNotificationId);

    try {
        mEqualizerHelper.releaseEQObjects();
        mEqualizerHelper = null;
    } catch (Exception e1) {
        e1.printStackTrace();
        mEqualizerHelper = null;
    }

    if (mMediaPlayer != null)
        mMediaPlayer.release();

    if (mMediaPlayer2 != null)
        getMediaPlayer2().release();

    mMediaPlayer = null;
    mMediaPlayer2 = null;

    //Close the cursor(s).
    try {
        getCursor().close();
        setCursor(null);
    } catch (Exception e) {
        e.printStackTrace();
    }

    //Final scrobbling.
    //scrobbleTrack(SimpleLastFMHelper.PAUSE);

    /*
     * If A-B repeat is enabled, disable it to prevent the
     * next service instance from repeating the same section
     * over and over on the new track.
     */
    if (getRepeatMode() == Common.A_B_REPEAT)
        setRepeatMode(Common.REPEAT_OFF);

    //Remove audio focus and unregister the audio buttons receiver.
    mAudioManagerHelper.setHasAudioFocus(false);
    mAudioManager.abandonAudioFocus(audioFocusChangeListener);
    mAudioManager.unregisterMediaButtonEventReceiver(
            new ComponentName(getPackageName(), HeadsetButtonsReceiver.class.getName()));
    mAudioManager = null;
    mMediaButtonReceiverComponent = null;
    mRemoteControlClientCompat = null;

    //Nullify the service object.
    mApp.setService(null);
    mApp.setIsServiceRunning(false);
    mApp = null;

}

From source file:com.example.sensingapp.SensingApp.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        //Show MAIN app without finishing current activity
        ActivityInfo ai = m_riHome.activityInfo;
        Intent startIntent = new Intent(Intent.ACTION_MAIN);
        startIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        startIntent.setComponent(new ComponentName(ai.packageName, ai.name));
        startActivitySafely(startIntent);
        return true;
    } else {//from ww  w .ja  v  a 2  s.  c  om
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.Duo.music.player.Services.AudioPlaybackService.java

/**
 * (non-Javadoc)/*from w  w w  . j  a va 2s  . com*/
 * @see android.app.Service#onDestroy()
 */
@Override
public void onDestroy() {

    //Notify the UI that the service is about to stop.
    mApp.broadcastUpdateUICommand(new String[] { Common.SERVICE_STOPPING }, new String[] { "" });

    //Fire a broadcast message to the widget(s) to update them.
    updateWidgets();

    //Send service stop event to GAnalytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled()) {
            mTracker.set(Fields.SESSION_CONTROL, "end");
            mTracker.send(
                    MapBuilder.createTiming("Jams Service", System.currentTimeMillis() - mServiceStartTime,
                            "Service duration.", "User stopped music playback.").build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    //Save the last track's info within the current queue.
    try {
        mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION",
                getCurrentMediaPlayer().getCurrentPosition());
    } catch (Exception e) {
        e.printStackTrace();
        mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION", 0);
    }

    //If the current song is repeating a specific range, reset the repeat option.
    if (getRepeatMode() == Common.REPEAT_SONG) {
        setRepeatMode(Common.REPEAT_OFF);
    }

    mFadeInVolume = 0.0f;
    mFadeOutVolume = 1.0f;

    //Unregister the headset plug receiver and RemoteControlClient.
    try {
        RemoteControlHelper.unregisterRemoteControlClient(mAudioManager, mRemoteControlClientCompat);
        unregisterReceiver(mHeadsetPlugReceiver);
    } catch (Exception e) {
        //Just null out the receiver if it hasn't been registered yet.
        mHeadsetPlugReceiver = null;
    }

    //Remove the notification.
    NotificationManager notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
    notificationManager.cancel(mNotificationId);

    try {
        mEqualizerHelper.releaseEQObjects();
        mEqualizerHelper = null;
    } catch (Exception e1) {
        e1.printStackTrace();
        mEqualizerHelper = null;
    }

    if (mMediaPlayer != null)
        mMediaPlayer.release();

    if (mMediaPlayer2 != null)
        getMediaPlayer2().release();

    mMediaPlayer = null;
    mMediaPlayer2 = null;

    //Close the cursor(s).
    try {
        getCursor().close();
        setCursor(null);
    } catch (Exception e) {
        e.printStackTrace();
    }

    //Final scrobbling.
    scrobbleTrack(SimpleLastFMHelper.PAUSE);

    /*
     * If A-B repeat is enabled, disable it to prevent the
     * next service instance from repeating the same section
     * over and over on the new track.
     */
    if (getRepeatMode() == Common.A_B_REPEAT)
        setRepeatMode(Common.REPEAT_OFF);

    //Remove audio focus and unregister the audio buttons receiver.
    mAudioManagerHelper.setHasAudioFocus(false);
    mAudioManager.abandonAudioFocus(audioFocusChangeListener);
    mAudioManager.unregisterMediaButtonEventReceiver(
            new ComponentName(getPackageName(), HeadsetButtonsReceiver.class.getName()));
    mAudioManager = null;
    mMediaButtonReceiverComponent = null;
    mRemoteControlClientCompat = null;

    //Nullify the service object.
    mApp.setService(null);
    mApp.setIsServiceRunning(false);
    mApp = null;

}

From source file:com.aniruddhc.acemusic.player.Services.AudioPlaybackService.java

/**
 * (non-Javadoc)/*from   www .  ja v a2  s . c o  m*/
 * @see android.app.Service#onDestroy()
 */
@Override
public void onDestroy() {

    //Notify the UI that the service is about to stop.
    mApp.broadcastUpdateUICommand(new String[] { Common.SERVICE_STOPPING }, new String[] { "" });

    //Fire a broadcast message to the widget(s) to update them.
    updateWidgets();

    //Send service stop event to GAnalytics.
    try {
        if (mApp.isGoogleAnalyticsEnabled()) {
            mTracker.set(Fields.SESSION_CONTROL, "end");
            mTracker.send(MapBuilder.createTiming("ACE Service", System.currentTimeMillis() - mServiceStartTime,
                    "Service duration.", "User stopped music playback.").build());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    //Save the last track's info within the current queue.
    try {
        mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION",
                getCurrentMediaPlayer().getCurrentPosition());
    } catch (Exception e) {
        e.printStackTrace();
        mApp.getSharedPreferences().edit().putLong("LAST_SONG_TRACK_POSITION", 0);
    }

    //If the current song is repeating a specific range, reset the repeat option.
    if (getRepeatMode() == Common.REPEAT_SONG) {
        setRepeatMode(Common.REPEAT_OFF);
    }

    mFadeInVolume = 0.0f;
    mFadeOutVolume = 1.0f;

    //Unregister the headset plug receiver and RemoteControlClient.
    try {
        RemoteControlHelper.unregisterRemoteControlClient(mAudioManager, mRemoteControlClientCompat);
        unregisterReceiver(mHeadsetPlugReceiver);
    } catch (Exception e) {
        //Just null out the receiver if it hasn't been registered yet.
        mHeadsetPlugReceiver = null;
    }

    //Remove the notification.
    NotificationManager notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
    notificationManager.cancel(mNotificationId);

    try {
        mEqualizerHelper.releaseEQObjects();
        mEqualizerHelper = null;
    } catch (Exception e1) {
        e1.printStackTrace();
        mEqualizerHelper = null;
    }

    if (mMediaPlayer != null)
        mMediaPlayer.release();

    if (mMediaPlayer2 != null)
        getMediaPlayer2().release();

    mMediaPlayer = null;
    mMediaPlayer2 = null;

    //Close the cursor(s).
    try {
        getCursor().close();
        setCursor(null);
    } catch (Exception e) {
        e.printStackTrace();
    }

    //Final scrobbling.
    scrobbleTrack(SimpleLastFMHelper.PAUSE);

    /*
     * If A-B repeat is enabled, disable it to prevent the
     * next service instance from repeating the same section
     * over and over on the new track.
     */
    if (getRepeatMode() == Common.A_B_REPEAT)
        setRepeatMode(Common.REPEAT_OFF);

    //Remove audio focus and unregister the audio buttons receiver.
    mAudioManagerHelper.setHasAudioFocus(false);
    mAudioManager.abandonAudioFocus(audioFocusChangeListener);
    mAudioManager.unregisterMediaButtonEventReceiver(
            new ComponentName(getPackageName(), HeadsetButtonsReceiver.class.getName()));
    mAudioManager = null;
    mMediaButtonReceiverComponent = null;
    mRemoteControlClientCompat = null;

    //Nullify the service object.
    mApp.setService(null);
    mApp.setIsServiceRunning(false);
    mApp = null;

}