List of usage examples for android.content Intent setComponent
public @NonNull Intent setComponent(@Nullable ComponentName component)
From source file:com.perm.DoomPlay.PlayingService.java
private RemoteViews getNotifViews(int layoutId) { RemoteViews views = new RemoteViews(getPackageName(), layoutId); Audio audio = audios.get(indexCurrentTrack); views.setTextViewText(R.id.notifTitle, audio.getTitle()); views.setTextViewText(R.id.notifArtist, audio.getArtist()); Bitmap cover = AlbumArtGetter.getBitmapFromStore(audio.getAid(), this); if (cover == null) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle();//from w w w . jav a 2 s .c o m } else { //TODO: java.lang.IllegalArgumentException: RemoteViews for widget update exceeds // maximum bitmap memory usage (used: 3240000, max: 2304000) // The total memory cannot exceed that required to fill the device's screen once try { views.setImageViewBitmap(R.id.notifAlbum, cover); } catch (IllegalArgumentException e) { Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover); views.setImageViewBitmap(R.id.notifAlbum, tempBitmap); tempBitmap.recycle(); } finally { cover.recycle(); } } views.setImageViewResource(R.id.notifPlay, isPlaying ? R.drawable.widget_pause : R.drawable.widget_play); ComponentName componentName = new ComponentName(this, PlayingService.class); Intent intentPlay = new Intent(actionPlay); intentPlay.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPlay, PendingIntent.getService(this, 0, intentPlay, 0)); Intent intentNext = new Intent(actionNext); intentNext.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifNext, PendingIntent.getService(this, 0, intentNext, 0)); Intent intentPrevious = new Intent(actionPrevious); intentPrevious.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifPrevious, PendingIntent.getService(this, 0, intentPrevious, 0)); Intent intentClose = new Intent(actionClose); intentClose.setComponent(componentName); views.setOnClickPendingIntent(R.id.notifClose, PendingIntent.getService(this, 0, intentClose, 0)); return views; }
From source file:github.madmarty.madsonic.util.Util.java
private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String arist = song.getArtist(); String album = song.getAlbum(); // Set the album art. try {//from w w w . j ava2s . c o m int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); if (bitmap == null) { // set default album art rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { rv.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { LOG.warn("Failed to get notification cover art", x); rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } rv.setImageViewResource(R.id.control_starred, song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); // set the text for the notifications rv.setTextViewText(R.id.notification_title, title); rv.setTextViewText(R.id.notification_artist, arist); rv.setTextViewText(R.id.notification_album, album); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { rv.setTextColor(R.id.notification_title, colors.getFirst()); } if (colors.getSecond() != null) { rv.setTextColor(R.id.notification_artist, colors.getSecond()); } if (!playing) { rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play); rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop); } // Create actions for media buttons PendingIntent pendingIntent; if (playing) { Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } else { Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP"); prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0); rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent); } Intent starredIntent = new Intent("KEYCODE_MEDIA_STARRED"); starredIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); starredIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_STAR)); pendingIntent = PendingIntent.getService(context, 0, starredIntent, 0); rv.setOnClickPendingIntent(R.id.control_starred, pendingIntent); Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE"); pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); rv.setOnClickPendingIntent(R.id.control_pause, pendingIntent); Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT"); nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); rv.setOnClickPendingIntent(R.id.control_next, pendingIntent); }
From source file:com.example.yuen.e_carei.ShowAppointmentList.java
private void open(ApplicationInfo item) { // open app/* w ww . ja va2 s .c om*/ Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); resolveIntent.setPackage(item.packageName); List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(resolveIntent, 0); if (resolveInfoList != null && resolveInfoList.size() > 0) { ResolveInfo resolveInfo = resolveInfoList.get(0); String activityPackageName = resolveInfo.activityInfo.packageName; String className = resolveInfo.activityInfo.name; Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName componentName = new ComponentName(activityPackageName, className); intent.setComponent(componentName); startActivity(intent); } }
From source file:github.popeen.dsub.util.compat.RemoteControlClientLP.java
@Override public void register(Context context, ComponentName mediaButtonReceiverComponent) { downloadService = (DownloadService) context; mediaSession = new MediaSessionCompat(downloadService, "DSub MediaSession"); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mediaButtonReceiverComponent); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, mediaButtonIntent, 0);// w w w . java 2s . co m mediaSession.setMediaButtonReceiver(mediaPendingIntent); Intent activityIntent = new Intent(context, SubsonicFragmentActivity.class); activityIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0); mediaSession.setSessionActivity(activityPendingIntent); mediaSession.setFlags( MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mediaSession.setCallback(new EventCallback()); mediaSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC); mediaSession.setActive(true); Bundle sessionExtras = new Bundle(); sessionExtras.putBoolean(WEAR_BACKGROUND_THEME, true); sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_PREVIOUS, true); sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_NEXT, true); sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_PREVIOUS, true); sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_NEXT, true); mediaSession.setExtras(sessionExtras); imageLoader = SubsonicActivity.getStaticImageLoader(context); }
From source file:org.simlar.GcmBroadcastReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { Lg.init(context);// w w w . j a va 2 s . c o m final Bundle extras = intent.getExtras(); if (extras.isEmpty()) { Lg.e(LOGTAG, "received Google Cloud Messaging Event with empty extras"); return; } final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); if (gcm == null) { Lg.e(LOGTAG, "unable to instantiate Google Cloud Messaging"); return; } final String messageType = gcm.getMessageType(intent); if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { Lg.i(LOGTAG, "received: ", extras); startWakefulService(context, intent .setComponent(new ComponentName(context.getPackageName(), SimlarService.class.getName()))); setResultCode(Activity.RESULT_OK); } else if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { Lg.e(LOGTAG, "send error: ", extras); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { Lg.e(LOGTAG, "deleted messages on server: ", extras); } else { Lg.e(LOGTAG, "received Google Cloud Messaging Event with unknown message type: ", messageType); } }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static void linkButtons(Context context, RemoteViews views, boolean playerActive) { Intent intent = new Intent(context, playerActive ? DownloadActivity.class : MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent); views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent); // Emulate media button clicks. intent = new Intent("1"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_play, pendingIntent); intent = new Intent("2"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_next, pendingIntent); intent = new Intent("3"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_previous, pendingIntent); intent = new Intent("4"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_stop, pendingIntent); }
From source file:androidx.media.session.MediaButtonReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent == null || !Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction()) || !intent.hasExtra(Intent.EXTRA_KEY_EVENT)) { Log.d(TAG, "Ignore unsupported intent: " + intent); return;//from w w w . ja va 2 s .c om } ComponentName mediaButtonServiceComponentName = getServiceComponentByAction(context, Intent.ACTION_MEDIA_BUTTON); if (mediaButtonServiceComponentName != null) { intent.setComponent(mediaButtonServiceComponentName); startForegroundService(context, intent); return; } ComponentName mediaBrowserServiceComponentName = getServiceComponentByAction(context, MediaBrowserServiceCompat.SERVICE_INTERFACE); if (mediaBrowserServiceComponentName != null) { PendingResult pendingResult = goAsync(); Context applicationContext = context.getApplicationContext(); MediaButtonConnectionCallback connectionCallback = new MediaButtonConnectionCallback(applicationContext, intent, pendingResult); MediaBrowserCompat mediaBrowser = new MediaBrowserCompat(applicationContext, mediaBrowserServiceComponentName, connectionCallback, null); connectionCallback.setMediaBrowser(mediaBrowser); mediaBrowser.connect(); return; } throw new IllegalStateException("Could not find any Service that handles " + Intent.ACTION_MEDIA_BUTTON + " or implements a media browser service."); }
From source file:com.gamethrive.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Google Play services started sending an extra non-ordered broadcast with the bundle: // { "COM": "RST_FULL", "from": "google.com/iid" } // Result codes are not valid with non-ordered broadcasts so omit it to prevent errors to the log. Bundle bundle = intent.getExtras();/* ww w. ja v a2 s .co m*/ if (bundle == null || "google.com/iid".equals(bundle.getString("from"))) return; // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); }
From source file:com.android.purenexussettings.TinkerActivity.java
public void launchcLock() { Intent link = new Intent(Intent.ACTION_MAIN); ComponentName cn = new ComponentName(KEY_LOCK_CLOCK_PACKAGE_NAME, KEY_LOCK_CLOCK_CLASS_NAME); link.setComponent(cn); startActivity(link);// w w w . j a v a 2s.c om }
From source file:com.phonemetra.deskclock.DeskClock.java
private boolean processMenuClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_settings: startActivity(new Intent(DeskClock.this, SettingsActivity.class)); return true; case R.id.menu_item_widget_settings: Intent wsi = new Intent(); wsi.setComponent(sWidgetSettingComponentName); try {// w ww .jav a2 s .co m startActivity(wsi); } catch (ActivityNotFoundException e) { Toast.makeText(this, getResources().getString(R.string.activity_not_found), Toast.LENGTH_SHORT) .show(); Log.w(LOG_TAG, "Cannot find the activity!"); } return true; case R.id.menu_item_help: Intent i = item.getIntent(); if (i != null) { try { startActivity(i); } catch (ActivityNotFoundException e) { // No activity found to match the intent - ignore } } return true; case R.id.menu_item_night_mode: startActivity(new Intent(DeskClock.this, ScreensaverActivity.class)); default: break; } return true; }