List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.andrew.apollo.NotificationHelper.java
/** * @param which Which {@link PendingIntent} to return * @return A {@link PendingIntent} ready to control playback *//*from w ww . jav a 2 s .c om*/ private final PendingIntent retreivePlaybackActions(final int which) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(mService, MusicPlaybackService.class); switch (which) { case 1: // Play and pause action = new Intent(MusicPlaybackService.TOGGLEPAUSE_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 1, action, 0); return pendingIntent; case 2: // Skip tracks action = new Intent(MusicPlaybackService.NEXT_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 2, action, 0); return pendingIntent; case 3: // Previous tracks action = new Intent(MusicPlaybackService.PREVIOUS_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 3, action, 0); return pendingIntent; case 4: // Stop and collapse the notification action = new Intent(MusicPlaybackService.STOP_ACTION); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 4, action, 0); return pendingIntent; default: break; } return null; }
From source file:com.boko.vimusic.NotificationHelper.java
/** * @param which// w w w.j a v a2s. c o m * Which {@link PendingIntent} to return * @return A {@link PendingIntent} ready to control playback */ private final PendingIntent retreivePlaybackActions(final int which) { Intent action; PendingIntent pendingIntent; final ComponentName serviceName = new ComponentName(mService, MediaPlaybackService.class); switch (which) { case 1: // Play and pause action = new Intent(MediaPlaybackService.ACTION_PLAYER_TOGGLEPAUSE); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 1, action, 0); return pendingIntent; case 2: // Skip tracks action = new Intent(MediaPlaybackService.ACTION_PLAYER_NEXT); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 2, action, 0); return pendingIntent; case 3: // Previous tracks action = new Intent(MediaPlaybackService.ACTION_PLAYER_PREVIOUS); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 3, action, 0); return pendingIntent; case 4: // Stop and collapse the notification action = new Intent(MediaPlaybackService.ACTION_PLAYER_STOP); action.setComponent(serviceName); pendingIntent = PendingIntent.getService(mService, 4, action, 0); return pendingIntent; default: break; } return null; }
From source file:com.measurence.sdk.android.gcm_push_notifications.GcmPushNotificationsReceiver.java
@Override public void onReceive(Context context, Intent intent) { final String LOG_TAG = context.getString(R.string.log_prefix) + " " + GcmPushNotificationsReceiver.class.getSimpleName(); Log.v(LOG_TAG, "Received intent"); // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), PresenceSessionUpdatesNotificationService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK);/* ww w .j a v a 2s . c o m*/ Log.v(LOG_TAG, "Intent processed"); }
From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java
private Intent makeMyIntent() { Intent intent = new Intent(getIntent()); intent.setComponent(null); // The resolver activity is set to be hidden from recent tasks. // we don't want this attribute to be propagated to the next activity // being launched. Note that if the original Intent also had this // flag set, we are now losing it. That should be a very rare case // and we can live with this. intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); return intent; }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public Intent getWirelessAlertsIntent() { final Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(new ComponentName(CMAS_COMPONENT, CELL_BROADCAST_LIST_ACTIVITY)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; }
From source file:com.gumgoose.app.quakebuddy.EarthquakeActivity.java
private static void openGooglePlay(Context context) { // Open Google Play app or browser equivalent to QuakeBuddy's page Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())); boolean marketFound = false; // Find all apps able to handle the rating intent final List<ResolveInfo> otherApps = context.getPackageManager().queryIntentActivities(rateIntent, 0); for (ResolveInfo otherApp : otherApps) { // Locate the Google Play app if (otherApp.activityInfo.applicationInfo.packageName.equals("com.android.vending")) { ActivityInfo otherAppActivity = otherApp.activityInfo; ComponentName componentName = new ComponentName(otherAppActivity.applicationInfo.packageName, otherAppActivity.name); // Ensure Google Play opens on a new task rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Reparent the task if needed rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); // Handle if Google Play is already open rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Ensure that only Google Play catches the intent rateIntent.setComponent(componentName); context.startActivity(rateIntent); marketFound = true;//from www. ja va2s . co m break; } } if (!marketFound) { // Google Play was not found, open web browser instead Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName())); context.startActivity(webIntent); } }
From source file:kr.go.hf.hfappandroid.app.intro.IntroActivity.java
/** * ???????VGuard??( ?? ? ?? )//from ww w . jav a 2 s . co m * * @date BSJ 13/05/06 */ private void startVGuard() { if (!Common.isPackageInstalled(this, Constants.VGUARD_PACKAGE_NAME)) { dialogInstallVGuard(); return; } ComponentName cn = new ComponentName(Constants.VGUARD_PACKAGE_NAME, Constants.VGUARD_PACKAGE_NAME + Constants.VGUARD_ACTIVITY_NAME); Intent actIntent = new Intent(Intent.ACTION_MAIN); actIntent.setComponent(cn); actIntent.addCategory(Intent.CATEGORY_LAUNCHER); actIntent.putExtra("LicenseKey", Constants.VGUARD_LICENSE_KEY); startActivityForResult(actIntent, REQUEST_START_VGUARD); CLog.e("VGuard", "start"); }
From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java
/** * Register the RemoteControlClient/*from w w w . j av a 2 s. com*/ */ private void registerRemoteControlClient() { // Request AudioFocus, so the widget is shown on the lock-screen mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); mAudioManager.registerMediaButtonEventReceiver(mClementineMediaButtonEventReceiver); // Create the intent Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mClementineMediaButtonEventReceiver); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(App.mApp.getApplicationContext(), 0, mediaButtonIntent, 0); // Create the client mRcClient = new RemoteControlClient(mediaPendingIntent); if (App.mClementine.getState() == Clementine.State.PLAY) { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); } else { mRcClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED); } mRcClient.setTransportControlFlags( RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE); mAudioManager.registerRemoteControlClient(mRcClient); }
From source file:nuclei.media.MediaService.java
@Override public void onCreate() { super.onCreate(); LOG.d("onCreate"); mPackageValidator = new PackageValidator(this); boolean casting = false; try {//from www. j av a 2 s. c o m VideoCastManager.getInstance().addVideoCastConsumer(mCastConsumer); casting = VideoCastManager.getInstance().isConnected() || VideoCastManager.getInstance().isConnecting(); } catch (IllegalStateException err) { LOG.e("Error registering cast consumer : " + err.getMessage()); } Playback playback; // Start a new MediaSession mSession = new MediaSessionCompat(this, "NucleiMediaService", new ComponentName(getApplicationContext(), MediaButtonReceiver.class), null); mSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mMediaRouter = MediaRouter.getInstance(getApplicationContext()); setSessionToken(mSession.getSessionToken()); try { mMediaNotificationManager = new MediaNotificationManager(this); } catch (RemoteException e) { throw new IllegalStateException("Could not create a MediaNotificationManager", e); } mSessionExtras = new Bundle(); if (casting) { mSessionExtras.putString(EXTRA_CONNECTED_CAST, VideoCastManager.getInstance().getDeviceName()); mMediaRouter.setMediaSessionCompat(mSession); playback = PlaybackFactory.createCastPlayback(MediaService.this); } else playback = PlaybackFactory.createLocalPlayback(MediaService.this); mPlaybackManager = new PlaybackManager(this, playback); mSession.setCallback(mPlaybackManager.getMediaSessionCallback()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(new ComponentName(this, MediaService.class)); mSession.setMediaButtonReceiver(PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0)); CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true); mSession.setExtras(mSessionExtras); mPlaybackManager.updatePlaybackState(null, true); registerCarConnectionReceiver(); }
From source file:be.ugent.zeus.hydra.util.audiostream.MusicService.java
/** * Starts playing the next song. If manualUrl is null, the next song will be randomly selected * from our Media Retriever (that is, it will be a random song in the user's device). If * manualUrl is non-null, then it specifies the URL or path to the song that will be played * next./* w ww. j a v a 2 s .c o m*/ */ void playmp3(String mp3url) { mState = State.Stopped; relaxResources(false); // release everything except MediaPlayer try { // set the source of the media player to a manual URL or path createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mPlayer.setDataSource(mp3url); mIsStreaming = true; mSongTitle = "Urgent.fm"; mState = State.Preparing; setUpAsForeground(mSongTitle + " (loading)"); // Use the media button APIs (if available) to register ourselves for media button // events MediaButtonHelper.registerMediaButtonEventReceiverCompat(mAudioManager, mMediaButtonReceiverComponent); // Use the remote control APIs (if available) to set the playback state if (mRemoteControlClientCompat == null) { Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); intent.setComponent(mMediaButtonReceiverComponent); mRemoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast( this /*context*/, 0 /*requestCode, ignored*/, intent /*intent*/, 0 /*flags*/)); RemoteControlHelper.registerRemoteControlClient(mAudioManager, mRemoteControlClientCompat); } mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING); mRemoteControlClientCompat.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP); // Update the remote controls mRemoteControlClientCompat.editMetadata(true) .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, "Urgent.fm") .putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, mDummyAlbumArt) .apply(); // starts preparing the media player in the background. When it's done, it will call // our OnPreparedListener (that is, the onPrepared() method on this class, since we set // the listener to 'this'). // // Until the media player is prepared, we *cannot* call start() on it! mPlayer.prepareAsync(); // If we are streaming from the internet, we want to hold a Wifi lock, which prevents // the Wifi radio from going to sleep while the song is playing. If, on the other hand, // we are *not* streaming, we want to release the lock if we were holding it before. if (mIsStreaming) { mWifiLock.acquire(); } else if (mWifiLock.isHeld()) { mWifiLock.release(); } } catch (IOException ex) { Log.e("MusicService", "IOException playing next song: " + ex.getMessage()); ex.printStackTrace(); } }