List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.mb.android.playbackmediator.notification.VideoCastNotificationService.java
private void addPendingIntents(RemoteViews rv, boolean isPlaying, SessionInfoDto info) { Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK); playbackIntent.setPackage(getPackageName()); PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0); Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); rv.setOnClickPendingIntent(R.id.playPauseView, playbackPendingIntent); rv.setOnClickPendingIntent(R.id.removeView, stopPendingIntent); if (isPlaying) { if (info.getNowPlayingItem().getRunTimeTicks() == null) { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_stop_sm_dark); } else {/*from w w w .j a v a2 s .c o m*/ rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_pause_sm_dark); } } else { rv.setImageViewResource(R.id.playPauseView, R.drawable.ic_av_play_sm_dark); } }
From source file:com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void buildForLollipopAndAbove(MediaInfo info, Bitmap bitmap, boolean isPlaying) throws CastException, TransientNetworkDisconnectionException, NoConnectionException { // Playback PendingIntent Intent playbackIntent = new Intent(ACTION_TOGGLE_PLAYBACK); playbackIntent.setPackage(getPackageName()); PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(this, 0, playbackIntent, 0); // Disconnect PendingIntent Intent stopIntent = new Intent(ACTION_STOP); stopIntent.setPackage(getPackageName()); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); // Main Content PendingIntent Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation()); Intent contentIntent = new Intent(this, mTargetActivity); contentIntent.putExtra("media", mediaWrapper); // Media metadata MediaMetadata mm = info.getMetadata(); String castingTo = getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(mTargetActivity); stackBuilder.addNextIntent(contentIntent); if (stackBuilder.getIntentCount() > 1) { stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper); }/* ww w .j a va2 s.c o m*/ PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT); mNotification = new Notification.Builder(this).setSmallIcon(R.drawable.ic_stat_action_notification) .setContentTitle(mm.getString(MediaMetadata.KEY_TITLE)).setContentText(castingTo) .setContentIntent(contentPendingIntent).setLargeIcon(bitmap) .addAction(isPlaying ? R.drawable.ic_pause_white_48dp : R.drawable.ic_play_arrow_white_48dp, getString(R.string.pause), playbackPendingIntent) .addAction(R.drawable.ic_clear_white_24dp, getString(R.string.disconnect), stopPendingIntent) .setStyle(new Notification.MediaStyle().setShowActionsInCompactView(new int[] { 0, 1 })) .setOngoing(true).setShowWhen(false).setVisibility(Notification.VISIBILITY_PUBLIC).build(); }
From source file:com.parse.ParsePushBroadcastReceiver.java
/** * Creates a {@link Notification} with reasonable defaults. If "alert" and "title" are * both missing from data, then returns {@code null}. If the text in the notification is longer * than 38 characters long, the style of the notification will be set to * {@link android.app.Notification.BigTextStyle}. * <p/>//from ww w . ja va 2 s.co m * As a security precaution, developers overriding this method should be sure to set the package * on notification {@code Intent}s to avoid leaking information to other apps. * * @param context * The {@code Context} in which the receiver is running. * @param intent * An {@code Intent} containing the channel and data of the current push notification. * @return * The notification to be displayed. * * @see ParsePushBroadcastReceiver#onPushReceive(Context, Intent) */ protected Notification getNotification(Context context, Intent intent) { JSONObject pushData = getPushData(intent); if (pushData == null || (!pushData.has("alert") && !pushData.has("title"))) { return null; } String title = pushData.optString("title", ManifestInfo.getDisplayName(context)); String alert = pushData.optString("alert", "Notification received."); String tickerText = String.format(Locale.getDefault(), "%s: %s", title, alert); Bundle extras = intent.getExtras(); Random random = new Random(); int contentIntentRequestCode = random.nextInt(); int deleteIntentRequestCode = random.nextInt(); // Security consideration: To protect the app from tampering, we require that intent filters // not be exported. To protect the app from information leaks, we restrict the packages which // may intercept the push intents. String packageName = context.getPackageName(); Intent contentIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_OPEN); contentIntent.putExtras(extras); contentIntent.setPackage(packageName); Intent deleteIntent = new Intent(ParsePushBroadcastReceiver.ACTION_PUSH_DELETE); deleteIntent.putExtras(extras); deleteIntent.setPackage(packageName); PendingIntent pContentIntent = PendingIntent.getBroadcast(context, contentIntentRequestCode, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pDeleteIntent = PendingIntent.getBroadcast(context, deleteIntentRequestCode, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); // The purpose of setDefaults(Notification.DEFAULT_ALL) is to inherit notification properties // from system defaults NotificationCompat.Builder parseBuilder = new NotificationCompat.Builder(context); parseBuilder.setContentTitle(title).setContentText(alert).setTicker(tickerText) .setSmallIcon(this.getSmallIconId(context, intent)).setLargeIcon(this.getLargeIcon(context, intent)) .setContentIntent(pContentIntent).setDeleteIntent(pDeleteIntent).setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL); if (alert != null && alert.length() > ParsePushBroadcastReceiver.SMALL_NOTIFICATION_MAX_CHARACTER_LIMIT) { parseBuilder.setStyle(new NotificationCompat.Builder.BigTextStyle().bigText(alert)); } return parseBuilder.build(); }
From source file:com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService.java
/** * Returns the {@link NotificationCompat.Action} for rewinding the current media by * {@code millis} milliseconds./* w w w . j a va 2 s. c o m*/ */ protected NotificationCompat.Action getRewindAction(long millis) { Intent intent = new Intent(ACTION_REWIND); intent.setPackage(getPackageName()); intent.putExtra(EXTRA_FORWARD_STEP_MS, (int) -millis); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); int iconResourceId = R.drawable.ic_notification_rewind_48dp; if (millis == TEN_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_rewind10_48dp; } else if (millis == THIRTY_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_rewind30_48dp; } return new NotificationCompat.Action.Builder(iconResourceId, getString(R.string.ccl_rewind), pendingIntent) .build(); }
From source file:com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService.java
/** * Returns the {@link NotificationCompat.Action} for forwarding the current media by * {@code millis} milliseconds.//from w w w.j a v a 2 s. c om */ protected NotificationCompat.Action getForwardAction(long millis) { Intent intent = new Intent(ACTION_FORWARD); intent.setPackage(getPackageName()); intent.putExtra(EXTRA_FORWARD_STEP_MS, (int) millis); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); int iconResourceId = R.drawable.ic_notification_forward_48dp; if (millis == TEN_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_forward10_48dp; } else if (millis == THIRTY_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_forward30_48dp; } return new NotificationCompat.Action.Builder(iconResourceId, getString(R.string.ccl_forward), pendingIntent) .build(); }
From source file:com.limemobile.app.plugin.PluginHostDelegateFragmentActivity.java
@Override public void startActivity(Intent intent, Bundle options) { List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfos == null || resolveInfos.isEmpty()) { intent.setPackage(mDelegatedActivity.getPackageName()); } else {/*from www .j av a 2 s . c o m*/ super.startActivity(intent, options); return; } PluginClientManager.sharedInstance(this).startActivity(this, intent, options); }
From source file:com.limemobile.app.plugin.PluginHostDelegateFragmentActivity.java
@Override public void startActivityForResult(Intent intent, int requestCode) { List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfos == null || resolveInfos.isEmpty()) { intent.setPackage(mDelegatedActivity.getPackageName()); } else {// ww w. j a v a2s. c o m super.startActivityForResult(intent, requestCode); return; } PluginClientManager.sharedInstance(this).startActivityForResult(this, intent, requestCode); }
From source file:com.parse.ParsePushBroadcastReceiver.java
/** * Called when the push notification is received. By default, a broadcast intent will be sent if * an "action" is present in the data and a notification will be show if "alert" and "title" are * present in the data./*from www .ja v a 2 s. c o m*/ * * @param context * The {@code Context} in which the receiver is running. * @param intent * An {@code Intent} containing the channel and data of the current push notification. */ protected void onPushReceive(Context context, Intent intent) { String pushDataStr = intent.getStringExtra(KEY_PUSH_DATA); if (pushDataStr == null) { PLog.e(TAG, "Can not get push data from intent."); return; } PLog.v(TAG, "Received push data: " + pushDataStr); JSONObject pushData = null; try { pushData = new JSONObject(pushDataStr); } catch (JSONException e) { PLog.e(TAG, "Unexpected JSONException when receiving push data: ", e); } // If the push data includes an action string, that broadcast intent is fired. String action = null; if (pushData != null) { action = pushData.optString("action", null); } if (action != null) { Bundle extras = intent.getExtras(); Intent broadcastIntent = new Intent(); broadcastIntent.putExtras(extras); broadcastIntent.setAction(action); broadcastIntent.setPackage(context.getPackageName()); context.sendBroadcast(broadcastIntent); } Notification notification = getNotification(context, intent); if (notification != null) { ParseNotificationManager.getInstance().showNotification(context, notification); } }
From source file:com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService.java
/** * Returns the {@link NotificationCompat.Action} for skipping to the next item in the queue. If * we are already at the end of the queue, we show a dimmed version of the icon for this action * and won't send any {@link PendingIntent} *///from w w w . ja v a2 s .co m protected NotificationCompat.Action getSkipNextAction() { PendingIntent pendingIntent = null; int iconResourceId = R.drawable.ic_notification_skip_next_semi_48dp; if (mHasNext) { Intent intent = new Intent(ACTION_PLAY_NEXT); intent.setPackage(getPackageName()); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); iconResourceId = R.drawable.ic_notification_skip_next_48dp; } return new NotificationCompat.Action.Builder(iconResourceId, getString(R.string.ccl_skip_next), pendingIntent).build(); }
From source file:com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService.java
/** * Returns the {@link NotificationCompat.Action} for skipping to the previous item in the queue. * If we are already at the beginning of the queue, we show a dimmed version of the icon for * this action and won't send any {@link PendingIntent} *//*from w w w . j ava2 s . co m*/ protected NotificationCompat.Action getSkipPreviousAction() { PendingIntent pendingIntent = null; int iconResourceId = R.drawable.ic_notification_skip_prev_semi_48dp; if (mHasPrev) { Intent intent = new Intent(ACTION_PLAY_PREV); intent.setPackage(getPackageName()); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); iconResourceId = R.drawable.ic_notification_skip_prev_48dp; } return new NotificationCompat.Action.Builder(iconResourceId, getString(R.string.ccl_skip_previous), pendingIntent).build(); }