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
/** * Broadcasts an {@link Intent} to inform the app to resend its notifications. *//*from ww w . ja v a2s . c om*/ public static void resendNotifications(final Context context, final Account account, final Folder folder) { LogUtils.i(LOG_TAG, "resendNotifications account: %s, folder: %s", LogUtils.sanitizeName(LOG_TAG, account.name), 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 ourself intent.putExtra(Utils.EXTRA_ACCOUNT_URI, account.uri); intent.putExtra(Utils.EXTRA_FOLDER_URI, folder.folderUri.fullUri); context.startService(intent); }
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
public static PendingIntent getUnpinActionIntent(Context context, int notificationId, Uri taskUri) { final Intent intent = new Intent(context, NotificationUpdaterService.class); intent.setAction(NotificationUpdaterService.ACTION_UNPIN); intent.setPackage(context.getPackageName()); intent.setData(taskUri);/*w ww . j av a2 s . c o m*/ intent.putExtra(EXTRA_NOTIFICATION_ID, notificationId); final PendingIntent pendingIntent = PendingIntent.getService(context, REQUEST_CODE_UNPIN, intent, PendingIntent.FLAG_CANCEL_CURRENT); return pendingIntent; }
From source file:com.chen.mail.utils.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} to be used for creating and canceling the undo timeout * alarm.//from w ww . j a va2 s .c o m */ private static PendingIntent createUndoTimeoutPendingIntent(final Context context, final NotificationAction notificationAction) { final Intent intent = new Intent(NotificationActionIntentService.ACTION_UNDO_TIMEOUT); intent.setPackage(context.getPackageName()); 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:org.dmfs.tasks.notification.NotificationUpdaterService.java
public static PendingIntent getCompleteActionIntent(Context context, int notificationId, Uri taskUri) { final Intent intent = new Intent(context, NotificationUpdaterService.class); intent.setAction(NotificationUpdaterService.ACTION_COMPLETE); intent.setPackage(context.getPackageName()); intent.setData(taskUri);/*ww w . java2s .c o m*/ intent.putExtra(EXTRA_NOTIFICATION_ID, notificationId); final PendingIntent pendingIntent = PendingIntent.getService(context, REQUEST_CODE_COMPLETE, intent, 0); return pendingIntent; }
From source file:com.shareyourproxy.IntentLauncher.java
/** * Send SMS to phone number on Hangouts. * * @param activity context//from ww w .ja v a 2s . c o m * @param actionAddress to contactId */ public static void launchHangoutsIntent(Activity activity, String actionAddress) { StringBuilder sb = new StringBuilder("content://com.android.contacts/data/").append(actionAddress); Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(sb.toString())); intent.setPackage("com.google.android.talk"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(activity.getPackageManager()) != null) { activity.startActivity(intent); } }
From source file:com.enstage.wibmo.sdk.inapp.InAppInitActivity.java
public static void startInAppReadinessCheck(Activity activity) { Log.d(TAG, "startInAppReadinessCheck"); String targetAppPackage = WibmoSDK.getWibmoIntentActionPackage(); Intent intent = new Intent(targetAppPackage + ".ReadinessChecker"); intent.addCategory(Intent.CATEGORY_DEFAULT); if (WibmoSDK.getWibmoAppPackage() != null) { intent.setPackage(WibmoSDK.getWibmoAppPackage()); }/*from w w w. jav a 2s . co m*/ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); //causes to iap to be cancelled when app returned by icon launch activity.startActivityForResult(intent, REQUEST_CODE_IAP_READY); }
From source file:com.onesignal.GenerateNotification.java
static void setStatics(Context inContext) { currentContext = inContext;/*from www .j a v a 2 s. co m*/ packageName = currentContext.getPackageName(); contextResources = currentContext.getResources(); PackageManager packageManager = currentContext.getPackageManager(); Intent intent = new Intent(currentContext, NotificationOpenedReceiver.class); intent.setPackage(currentContext.getPackageName()); if (packageManager.queryBroadcastReceivers(intent, 0).size() > 0) { openerIsBroadcast = true; notificationOpenedClass = NotificationOpenedReceiver.class; } else notificationOpenedClass = NotificationOpenedActivity.class; }
From source file:com.chen.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.stat_notify_email); 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); 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);// w w w . j a v a 2s.c o m // When the notification is cleared, we perform the destructive action final Intent deleteIntent = new Intent(NotificationActionIntentService.ACTION_DESTRUCT); deleteIntent.setPackage(packageName); 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:org.dmfs.tasks.notification.NotificationUpdaterService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static Notification makePinNotification(Context context, Builder builder, ContentSet task, boolean withSound, boolean withTickerText, boolean withHeadsUpNotification) { Resources resources = context.getResources(); // reset actions builder.mActions = new ArrayList<Action>(2); // content// w ww . ja v a2 s .c om builder.setSmallIcon(R.drawable.ic_pin_white_24dp).setContentTitle(TaskFieldAdapters.TITLE.get(task)) .setOngoing(true).setShowWhen(false); // set priority for HeadsUpNotification if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { if (withHeadsUpNotification) { builder.setPriority(Notification.PRIORITY_HIGH); } else { builder.setPriority(Notification.PRIORITY_DEFAULT); } } // color is based on the priority of the task. If the task has no priority we use the primary color. Integer priority = TaskFieldAdapters.PRIORITY.get(task); if (priority != null && priority > 0) { if (priority < 5) { builder.setColor(resources.getColor(R.color.priority_red)); } if (priority == 5) { builder.setColor(resources.getColor(R.color.priority_yellow)); } if (priority > 5 && priority <= 9) { builder.setColor(resources.getColor(R.color.priority_green)); } } else { builder.setColor(resources.getColor(R.color.colorPrimary)); } // description String contentText = makePinNotificationContentText(context, task); if (contentText != null) { builder.setContentText(contentText); } // ticker text if (withTickerText) { builder.setTicker( context.getString(R.string.notification_task_pin_ticker, (TaskFieldAdapters.TITLE.get(task)))); } // click action Intent resultIntent = new Intent(Intent.ACTION_VIEW); resultIntent.setData(task.getUri()); resultIntent.setPackage(context.getPackageName()); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); // complete action Boolean closed = TaskFieldAdapters.IS_CLOSED.get(task); if (closed == null || !closed) { Time dueTime = TaskFieldAdapters.DUE.get(task); long dueTimestamp = dueTime == null ? 0 : dueTime.toMillis(true); NotificationAction completeAction = new NotificationAction(NotificationUpdaterService.ACTION_COMPLETE, R.string.notification_action_completed, TaskFieldAdapters.TASK_ID.get(task), task.getUri(), dueTimestamp); builder.addAction(NotificationUpdaterService.getCompleteAction(context, NotificationActionUtils.getNotificationActionPendingIntent(context, completeAction))); } // unpin action builder.addAction(NotificationUpdaterService.getUnpinAction(context, TaskFieldAdapters.TASK_ID.get(task), task.getUri())); // sound if (withSound) { builder.setDefaults(Notification.DEFAULT_ALL); } else { builder.setDefaults(Notification.DEFAULT_LIGHTS); } return builder.build(); }
From source file:com.tct.mail.widget.WidgetService.java
public static void configureValidWidgetIntents(Context context, RemoteViews remoteViews, int appWidgetId, Account account, final int folderType, final int folderCapabilities, final Uri folderUri, final Uri folderConversationListUri, final String folderDisplayName, Class<?> serviceClass) { remoteViews.setViewVisibility(R.id.widget_configuration, View.GONE); // Launch an intent to avoid ANRs final Intent intent = new Intent(context, serviceClass); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_TYPE, folderType); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CAPABILITIES, folderCapabilities); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_URI, folderUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_CONVERSATION_LIST_URI, folderConversationListUri); intent.putExtra(BaseWidgetProvider.EXTRA_FOLDER_DISPLAY_NAME, folderDisplayName); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.conversation_list, intent); remoteViews.setEmptyView(R.id.conversation_list, R.id.empty_conversation_list); //TS: zheng.zou 2015-08-11 EMAIL BUGFIX_1044483 ADD // Open mail app when click on header final Intent mailIntent = Utils.createViewFolderIntent(context, folderUri, account); PendingIntent clickIntent = PendingIntent.getActivity(context, 0, mailIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent); // On click intent for Compose final Intent composeIntent = new Intent(); composeIntent.setAction(Intent.ACTION_SEND); //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_S composeIntent.setPackage(context.getPackageName()); //TS: jian.xu 2015-4-24 EMAIL BUGFIX_984619 ADD_E composeIntent.putExtra(Utils.EXTRA_ACCOUNT, account.serialize()); composeIntent.setData(account.composeIntentUri); composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_TASK, true); composeIntent.putExtra(ComposeActivity.EXTRA_FROM_EMAIL_WIDGET, true); //TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 ADD if (account.composeIntentUri != null) { composeIntent.putExtra(Utils.EXTRA_COMPOSE_URI, account.composeIntentUri); }/*from w w w . j a v a 2s .c om*/ // Build a task stack that forces the conversation list on the stack before the compose // activity. final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); clickIntent = taskStackBuilder.addNextIntent(mailIntent).addNextIntent(composeIntent).getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent); // On click intent for Conversation final Intent conversationIntent = new Intent(); conversationIntent.setAction(Intent.ACTION_VIEW); clickIntent = PendingIntent.getActivity(context, 0, conversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.conversation_list, clickIntent); }