List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.chen.mail.utils.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} for the specified notification action. *//*from w w w .ja va 2s .c o m*/ private static PendingIntent getNotificationActionPendingIntent(final Context context, final Account account, final Conversation conversation, final Message message, final Folder folder, final Intent notificationIntent, final NotificationActionType action, final int notificationId, final long when) { final Uri messageUri = message.uri; final NotificationAction notificationAction = new NotificationAction(action, account, conversation, message, folder, conversation.id, message.serverId, message.id, when); switch (action) { case REPLY: { // Build a task stack that forces the conversation view on the stack before the // reply activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); final Intent intent = createReplyIntent(context, account, messageUri, false); intent.setPackage(context.getPackageName()); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); // To make sure that the reply intents one notification don't clobber over // intents for other notification, force a data uri on the intent final Uri notificationUri = Uri.parse("mailfrom://mail/account/" + "reply/" + notificationId); intent.setData(notificationUri); taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent); return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); } case REPLY_ALL: { // Build a task stack that forces the conversation view on the stack before the // reply activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); final Intent intent = createReplyIntent(context, account, messageUri, true); intent.setPackage(context.getPackageName()); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); // To make sure that the reply intents one notification don't clobber over // intents for other notification, force a data uri on the intent final Uri notificationUri = Uri.parse("mailfrom://mail/account/" + "replyall/" + notificationId); intent.setData(notificationUri); taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent); return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); } case ARCHIVE_REMOVE_LABEL: { final String intentAction = NotificationActionIntentService.ACTION_ARCHIVE_REMOVE_LABEL; final Intent intent = new Intent(intentAction); intent.setPackage(context.getPackageName()); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } case DELETE: { final String intentAction = NotificationActionIntentService.ACTION_DELETE; final Intent intent = new Intent(intentAction); intent.setPackage(context.getPackageName()); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } } throw new IllegalArgumentException("Invalid NotificationActionType"); }
From source file:dentex.youtube.downloader.utils.Utils.java
public static Intent createEmailOnlyChooserIntent(Context ctx, Intent source, CharSequence chooserTitle) { BugSenseHandler.leaveBreadcrumb("createEmailOnlyChooserIntent"); Stack<Intent> intents = new Stack<Intent>(); Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "info@domain.com", null)); List<ResolveInfo> activities = ctx.getPackageManager().queryIntentActivities(i, 0); for (ResolveInfo ri : activities) { Intent target = new Intent(source); target.setPackage(ri.activityInfo.packageName); intents.add(target);// w w w .ja va2s. com } if (!intents.isEmpty()) { Intent chooserIntent = Intent.createChooser(intents.remove(0), chooserTitle); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[intents.size()])); return chooserIntent; } else { return Intent.createChooser(source, chooserTitle); } }
From source file:com.android.email.EmailNotificationController.java
private static void refreshNotificationsForAccountInternal(final Context context, final long accountId) { final Uri accountUri = EmailProvider.uiUri("uiaccount", accountId); final ContentResolver contentResolver = context.getContentResolver(); final Cursor mailboxCursor = contentResolver.query( ContentUris.withAppendedId(EmailContent.MAILBOX_NOTIFICATION_URI, accountId), null, null, null, null);//w ww. j a va 2 s . c o m try { while (mailboxCursor.moveToNext()) { final long mailboxId = mailboxCursor.getLong(EmailContent.NOTIFICATION_MAILBOX_ID_COLUMN); if (mailboxId == 0) continue; final int unseenCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNSEEN_COUNT_COLUMN); final int unreadCount; // If nothing is unseen, clear the notification if (unseenCount == 0) { unreadCount = 0; } else { unreadCount = mailboxCursor.getInt(EmailContent.NOTIFICATION_MAILBOX_UNREAD_COUNT_COLUMN); } final Uri folderUri = EmailProvider.uiUri("uifolder", mailboxId); LogUtils.d(LOG_TAG, "Changes to account " + accountId + ", folder: " + mailboxId + ", unreadCount: " + unreadCount + ", unseenCount: " + unseenCount); final Intent intent = new Intent(UIProvider.ACTION_UPDATE_NOTIFICATION); intent.setPackage(context.getPackageName()); intent.setType(EmailProvider.EMAIL_APP_MIME_TYPE); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_ACCOUNT, accountUri); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_FOLDER, folderUri); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNREAD_COUNT, unreadCount); intent.putExtra(UIProvider.UpdateNotificationExtras.EXTRA_UPDATED_UNSEEN_COUNT, unseenCount); context.sendOrderedBroadcast(intent, null); } } finally { mailboxCursor.close(); } }
From source file:com.upnext.blekit.BLEKit.java
private static void restartBlekit(Context context) { Intent intnt = new Intent("com.upnext.blekit.service.RESTARTER"); intnt.setPackage(context.getPackageName()); if (context.getPackageManager().resolveService(intnt, 0) != null) { context.startService(intnt);//from w w w . j a v a 2 s .co m } }
From source file:com.android.mail.utils.NotificationActionUtils.java
/** * Broadcasts an {@link Intent} to inform the app to resend its notifications. *///from w w w . ja v a2 s. c o m public static void resendNotifications(final Context context, final Account account, final Folder folder) { LogUtils.i(LOG_TAG, "resendNotifications account: %s, folder: %s", account == null ? null : LogUtils.sanitizeName(LOG_TAG, account.getEmailAddress()), folder == null ? null : LogUtils.sanitizeName(LOG_TAG, folder.name)); final Intent intent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS); intent.setPackage(context.getPackageName()); // Make sure we only deliver this to ourselves if (account != null) { intent.putExtra(Utils.EXTRA_ACCOUNT_URI, account.uri); } if (folder != null) { intent.putExtra(Utils.EXTRA_FOLDER_URI, folder.folderUri.fullUri); } context.startService(intent); }
From source file:com.android.mail.utils.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} to be used for creating and canceling the undo timeout * alarm.// w w w .j a v a2 s . co m */ private static PendingIntent createUndoTimeoutPendingIntent(final Context context, final NotificationAction notificationAction) { final Intent intent = new Intent(NotificationActionIntentService.ACTION_UNDO_TIMEOUT); intent.setPackage(context.getPackageName()); intent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(intent, notificationAction); final int requestCode = notificationAction.getAccount().hashCode() ^ notificationAction.getFolder().hashCode(); final PendingIntent pendingIntent = PendingIntent.getService(context, requestCode, intent, 0); return pendingIntent; }
From source file:Main.java
public static void openMailChooser(Context context, String text, String[] mails, String subject) { Intent mailIntent = new Intent(); mailIntent.setAction(Intent.ACTION_SEND); mailIntent.putExtra(Intent.EXTRA_TEXT, text); mailIntent.putExtra(Intent.EXTRA_EMAIL, mails); mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); mailIntent.setType(INTENT_TYPE_MSG); PackageManager pm = context.getPackageManager(); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType(INTENT_TYPE_TEXT); Intent openInChooser = Intent.createChooser(mailIntent, ""); List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0); List<LabeledIntent> intentList = new ArrayList<LabeledIntent>(); for (ResolveInfo ri : resInfo) { String packageName = ri.activityInfo.packageName; if (packageName.contains(PACKAGE_EMAIL)) { mailIntent.setPackage(packageName); } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) { Intent intent = new Intent(); intent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); intent.setAction(Intent.ACTION_SEND); intent.setType(INTENT_TYPE_TEXT); if (packageName.contains(PACKAGE_MMS)) { intent.putExtra("subject", subject); intent.putExtra("sms_body", text); intent.putExtra("address", mails[0]); intent.setType(INTENT_TYPE_MSG); } else if (packageName.contains(PACKAGE_GMAIL)) { intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_EMAIL, mails); intent.setType(INTENT_TYPE_MSG); }//from w w w . j av a 2 s . c om intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon)); } } LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]); openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents); context.startActivity(openInChooser); }
From source file:com.tct.mail.utils.NotificationActionUtils.java
/** * Broadcasts an {@link Intent} to inform the app to resend its notifications. *//*from ww w . j a va2 s. c om*/ public static void resendNotifications(final Context context, final Account account, final Folder folder) { // Fix NPE when parameter is null in NotificationActionUtils LogUtils.i(LOG_TAG, "resendNotifications account: %s, folder: %s", LogUtils.sanitizeName(LOG_TAG, account == null ? "null" : account.getEmailAddress()), LogUtils.sanitizeName(LOG_TAG, folder == null ? "null" : folder.name)); //M upgrade: Bug: 17713589 Gmail crashes when accessing an old notification for an account that has been deleted. final Intent intent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS); intent.setPackage(context.getPackageName()); // Make sure we only deliver this to ourselves if (account != null) { intent.putExtra(Utils.EXTRA_ACCOUNT_URI, account.uri); } if (folder != null) { intent.putExtra(Utils.EXTRA_FOLDER_URI, folder.folderUri.fullUri); } context.startService(intent); }
From source file:com.android.mail.utils.NotificationActionUtils.java
public static Notification createUndoNotification(final Context context, final NotificationAction notificationAction, final int notificationId) { LogUtils.i(LOG_TAG, "createUndoNotification for %s", notificationAction.getNotificationActionType()); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_notification_mail_24dp); builder.setWhen(notificationAction.getWhen()); builder.setCategory(NotificationCompat.CATEGORY_EMAIL); final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification); undoView.setTextViewText(R.id.description_text, context.getString(notificationAction.getActionTextResId())); final String packageName = context.getPackageName(); final Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_UNDO); clickIntent.setPackage(packageName); clickIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(clickIntent, notificationAction); final PendingIntent clickPendingIntent = PendingIntent.getService(context, notificationId, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); undoView.setOnClickPendingIntent(R.id.status_bar_latest_event_content, clickPendingIntent); builder.setContent(undoView);//from w w w. j a v a 2 s . co m // When the notification is cleared, we perform the destructive action final Intent deleteIntent = new Intent(NotificationActionIntentService.ACTION_DESTRUCT); deleteIntent.setPackage(packageName); deleteIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(deleteIntent, notificationAction); final PendingIntent deletePendingIntent = PendingIntent.getService(context, notificationId, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deletePendingIntent); final Notification notification = builder.build(); return notification; }
From source file:com.tct.mail.utils.NotificationActionUtils.java
public static Notification createUndoNotification(final Context context, final NotificationAction notificationAction, final int notificationId) { LogUtils.i(LOG_TAG, "createUndoNotification for %s", notificationAction.getNotificationActionType()); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_notification_mail_24dp); builder.setWhen(notificationAction.getWhen()); final RemoteViews undoView = new RemoteViews(context.getPackageName(), R.layout.undo_notification); undoView.setTextViewText(R.id.description_text, context.getString(notificationAction.getActionTextResId())); final String packageName = context.getPackageName(); final Intent clickIntent = new Intent(NotificationActionIntentService.ACTION_UNDO); clickIntent.setPackage(packageName); clickIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(clickIntent, notificationAction); final PendingIntent clickPendingIntent = PendingIntent.getService(context, notificationId, clickIntent, PendingIntent.FLAG_CANCEL_CURRENT); undoView.setOnClickPendingIntent(R.id.status_bar_latest_event_content, clickPendingIntent); builder.setContent(undoView);//from w w w .j a va 2s . c om // When the notification is cleared, we perform the destructive action final Intent deleteIntent = new Intent(NotificationActionIntentService.ACTION_DESTRUCT); deleteIntent.setPackage(packageName); deleteIntent.setData(notificationAction.mConversation.uri); putNotificationActionExtra(deleteIntent, notificationAction); final PendingIntent deletePendingIntent = PendingIntent.getService(context, notificationId, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setDeleteIntent(deletePendingIntent); final Notification notification = builder.build(); return notification; }