List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.ifoer.expeditionphone.MainActivity.java
private void openApp() throws NameNotFoundException { PackageInfo pi = getPackageManager().getPackageInfo("com.cnlaunch.golo3", 0); Intent resolveIntent = new Intent("android.intent.action.MAIN", null); resolveIntent.addCategory("android.intent.category.LAUNCHER"); resolveIntent.setPackage(pi.packageName); ResolveInfo ri = (ResolveInfo) getPackageManager().queryIntentActivities(resolveIntent, 0).iterator() .next();/*w w w. j a va2 s .com*/ if (ri != null) { String packageName1 = ri.activityInfo.packageName; String className = ri.activityInfo.name; Intent intent = new Intent("android.intent.action.MAIN"); intent.addCategory("android.intent.category.LAUNCHER"); intent.setComponent(new ComponentName(packageName1, className)); startActivity(intent); } }
From source file:com.andrew.apolloMod.service.ApolloService.java
@SuppressLint({ "WorldWriteableFiles", "WorldReadableFiles" }) @Override/*from w ww . ja v a 2 s .c o m*/ public void onCreate() { super.onCreate(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(rec); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(rec); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (Constants.isApi14Supported()) { mRemoteControlClient = new RemoteControlClient(mediaPendingIntent); mAudioManager.registerRemoteControlClient(mRemoteControlClient); int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP; mRemoteControlClient.setTransportControlFlags(flags); } mPreferences = getSharedPreferences(APOLLO_PREFERENCES, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE); mCardId = MusicUtils.getCardId(this); registerExternalStorageListener(); // Needs to be done in this thread, since otherwise // ApplicationContext.getPowerManager() crashes. mPlayer = new MultiPlayer(); mPlayer.setHandler(mMediaplayerHandler); reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(SERVICECMD); commandFilter.addAction(TOGGLEPAUSE_ACTION); commandFilter.addAction(PAUSE_ACTION); commandFilter.addAction(NEXT_ACTION); commandFilter.addAction(PREVIOUS_ACTION); commandFilter.addAction(CYCLEREPEAT_ACTION); commandFilter.addAction(TOGGLESHUFFLE_ACTION); registerReceiver(mIntentReceiver, commandFilter); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); // If the service was idle, but got killed before it stopped itself, the // system will relaunch it. Make sure it gets stopped again in that // case. Message msg = mDelayedStopHandler.obtainMessage(); mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY); }
From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java
/** * Constructs an intent from the given information and the search dialog state. * * @param action Intent action.//from w ww . jav a 2 s .c o m * @param data Intent data, or <code>null</code>. * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>. * @param query Intent query, or <code>null</code>. * @param actionKey The key code of the action key that was pressed, * or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed, * or <code>null</code> if none. * @return The intent. */ private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey, String actionMsg) { // Now build the Intent Intent intent = new Intent(action); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // We need CLEAR_TOP to avoid reusing an old task that has other activities // on top of the one we want. We don't want to do this in in-app search though, // as it can be destructive to the activity stack. if (data != null) { intent.setData(data); } intent.putExtra(SearchManager.USER_QUERY, mUserQuery); if (query != null) { intent.putExtra(SearchManager.QUERY, query); } if (extraData != null) { intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); } if (mAppSearchData != null) { intent.putExtra(SearchManager.APP_DATA, mAppSearchData); } if (actionKey != KeyEvent.KEYCODE_UNKNOWN) { intent.putExtra(SearchManager.ACTION_KEY, actionKey); intent.putExtra(SearchManager.ACTION_MSG, actionMsg); } intent.setComponent(mSearchable.getSearchActivity()); return intent; }
From source file:com.andrew.apolloMod.service.ApolloService.java
/** Return notification remote views * /*from www.j a v a 2s .c om*/ * @return [views, bigViews] */ public RemoteViews[] getNotificationViews() { Bitmap b = getAlbumBitmap(); RemoteViews bigViews = new RemoteViews(getPackageName(), R.layout.status_bar_expanded); RemoteViews views = new RemoteViews(getPackageName(), R.layout.status_bar); if (b != null) { bigViews.setImageViewBitmap(R.id.status_bar_album_art, b); views.setViewVisibility(R.id.status_bar_icon, View.GONE); views.setViewVisibility(R.id.status_bar_album_art, View.VISIBLE); views.setImageViewBitmap(R.id.status_bar_album_art, b); } else { views.setViewVisibility(R.id.status_bar_icon, View.VISIBLE); views.setViewVisibility(R.id.status_bar_album_art, View.GONE); } ComponentName rec = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.putExtra(CMDNOTIF, 1); mediaButtonIntent.setComponent(rec); KeyEvent mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_play, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 2); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 2, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_next, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 4); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 4, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); bigViews.setOnClickPendingIntent(R.id.status_bar_prev, mediaPendingIntent); mediaButtonIntent.putExtra(CMDNOTIF, 3); mediaKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP); mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, mediaKey); mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 3, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); bigViews.setOnClickPendingIntent(R.id.status_bar_collapse, mediaPendingIntent); views.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); bigViews.setImageViewResource(R.id.status_bar_play, R.drawable.apollo_holo_dark_pause); views.setTextViewText(R.id.status_bar_track_name, getTrackName()); bigViews.setTextViewText(R.id.status_bar_track_name, getTrackName()); views.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_artist_name, getArtistName()); bigViews.setTextViewText(R.id.status_bar_album_name, getAlbumName()); return new RemoteViews[] { views, bigViews }; }
From source file:android.support.v7.widget.SearchView.java
/** * Constructs an intent from the given information and the search dialog state. * * @param action Intent action./* ww w. j av a 2 s.co m*/ * @param data Intent data, or <code>null</code>. * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>. * @param query Intent query, or <code>null</code>. * @param actionKey The key code of the action key that was pressed, * or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed, * or <code>null</code> if none. * @return The intent. */ private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey, String actionMsg) { // Now build the Intent Intent intent = new Intent(action); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // We need CLEAR_TOP to avoid reusing an old task that has other activities // on top of the one we want. We don't want to do this in in-app search though, // as it can be destructive to the activity stack. if (data != null) { intent.setData(data); } intent.putExtra(SearchManager.USER_QUERY, mUserQuery); if (query != null) { intent.putExtra(SearchManager.QUERY, query); } if (extraData != null) { intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); } if (mAppSearchData != null) { intent.putExtra(SearchManager.APP_DATA, mAppSearchData); } if (actionKey != KeyEvent.KEYCODE_UNKNOWN) { intent.putExtra(SearchManager.ACTION_KEY, actionKey); intent.putExtra(SearchManager.ACTION_MSG, actionMsg); } if (IS_AT_LEAST_FROYO) { intent.setComponent(mSearchable.getSearchActivity()); } return intent; }
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;/* w w w . j a v a 2 s .c om*/ } 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:de.mrapp.android.bottomsheet.BottomSheet.java
/** * Creates and returns a listener, which allows to start an app, when an item of the bottom * sheet has been clicked.//from w w w . j a va 2s. c om * * @param activity * The activity, the bottom sheet belongs to, as an instance of the class {@link * Activity}. The activity may not be null * @param intent * The intent, which should be passed to the started app, as an instance of the class * {@link Intent}. The intent may not be null * @param resolveInfos * A list, which contains the resolve infos, which correspond to the apps, which are * able to handle the intent, as an instance of the type {@link List} or an empty list, * if no apps are able to handle the intent * @return The listener, which has been created, as an instance of the type {@link * OnItemClickListener} */ private OnItemClickListener createIntentClickListener(@NonNull final Activity activity, @NonNull final Intent intent, @NonNull final List<ResolveInfo> resolveInfos) { return new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { ActivityInfo activityInfo = resolveInfos.get(position).activityInfo; ComponentName componentName = new ComponentName(activityInfo.applicationInfo.packageName, activityInfo.name); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.setComponent(componentName); activity.startActivity(intent); dismiss(); } }; }
From source file:com.example.navigationsearchview.NavigationSearchView.java
/** * Constructs an intent from the given information and the search dialog * state.//from www .jav a 2 s . c om * * @param action * Intent action. * @param data * Intent data, or <code>null</code>. * @param extraData * Data for {@link SearchManager#EXTRA_DATA_KEY} or * <code>null</code>. * @param query * Intent query, or <code>null</code>. * @param actionKey * The key code of the action key that was pressed, or * {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg * The message for the action key that was pressed, or * <code>null</code> if none. * @return The intent. */ private Intent createIntent(String action, Uri data, String extraData, String query, int actionKey, String actionMsg) { // Now build the Intent Intent intent = new Intent(action); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // We need CLEAR_TOP to avoid reusing an old task that has other // activities // on top of the one we want. We don't want to do this in in-app search // though, // as it can be destructive to the activity stack. if (data != null) { intent.setData(data); } intent.putExtra(SearchManager.USER_QUERY, mUserQuery); if (query != null) { intent.putExtra(SearchManager.QUERY, query); } if (extraData != null) { intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); } if (mAppSearchData != null) { intent.putExtra(SearchManager.APP_DATA, mAppSearchData); } if (actionKey != KeyEvent.KEYCODE_UNKNOWN) { intent.putExtra(SearchManager.ACTION_KEY, actionKey); intent.putExtra(SearchManager.ACTION_MSG, actionMsg); } if (IS_AT_LEAST_FROYO) { intent.setComponent(mSearchable.getSearchActivity()); } return intent; }
From source file:com.bluros.music.MusicService.java
private final PendingIntent retrievePlaybackAction(final String action) { final ComponentName serviceName = new ComponentName(this, MusicService.class); Intent intent = new Intent(action); intent.setComponent(serviceName); return PendingIntent.getService(this, 0, intent, 0); }