List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.android.mail.utils.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} for the specified notification action. */// w w w.ja va2 s . c om 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, NotificationAction.SOURCE_LOCAL, notificationId); 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.setData(conversation.uri); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); 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.setData(conversation.uri); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); 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()); intent.setData(conversation.uri); 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()); intent.setData(conversation.uri); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } } throw new IllegalArgumentException("Invalid NotificationActionType"); }
From source file:org.wso2.emm.agent.utils.CommonUtils.java
/** * Call EMM system app in COPE mode./*from w w w .j a va2 s .c om*/ * @param context - Application context. * @param operation - Operation code. * @param command - Shell command to be executed. * @param appUri - App package/APK URI when an app operation executed. */ public static void callSystemApp(Context context, String operation, String command, String appUri) { if (Constants.SYSTEM_APP_ENABLED) { Intent intent = new Intent(Constants.SYSTEM_APP_SERVICE_START_ACTION); Intent explicitIntent = createExplicitFromImplicitIntent(context, intent); if (explicitIntent != null) { intent = explicitIntent; } intent.putExtra(Constants.OPERATION_CODE, operation); intent.setPackage(Constants.AGENT_PACKAGE); if (appUri != null) { intent.putExtra("appUri", appUri); } if (command != null) { if (Constants.Operation.UPGRADE_FIRMWARE.equals(operation)) { try { JSONObject upgradeData = new JSONObject(command); if (upgradeData .isNull(context.getResources().getString(R.string.firmware_upgrade_automatic_retry)) && Preference.hasPreferenceKey(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade))) { boolean isFirmwareUpgradeAutoRetry = Preference.getBoolean(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade)); upgradeData.put( context.getResources().getString(R.string.firmware_upgrade_automatic_retry), isFirmwareUpgradeAutoRetry); command = upgradeData.toString(); Log.d(TAG, "Updated payload: " + command); } else if (!upgradeData.isNull( context.getResources().getString(R.string.firmware_upgrade_automatic_retry))) { Preference.putBoolean(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade), upgradeData.getBoolean(context.getResources() .getString(R.string.firmware_upgrade_automatic_retry))); } else { upgradeData.put( context.getResources().getString(R.string.firmware_upgrade_automatic_retry), true); Preference.putBoolean(context, context.getResources().getString(R.string.is_automatic_firmware_upgrade), true); Log.d(TAG, "Updated payload: " + command); } } catch (JSONException e) { Log.e(TAG, "Could not parse Firmware upgrade operation", e); } intent.putExtra("operationId", Preference.getInt(context, "firmwareOperationId")); } intent.putExtra("command", command); } context.startServiceAsUser(intent, android.os.Process.myUserHandle()); } else { Log.e(TAG, "System app not enabled."); } }
From source file:com.test.onesignal.MainOneSignalClassRunner.java
private static void AddLauncherIntentFilter() { Intent launchIntent = new Intent(Intent.ACTION_MAIN); launchIntent.setPackage("com.onesignal.example"); launchIntent.addCategory(Intent.CATEGORY_LAUNCHER); ResolveInfo resolveInfo = new ResolveInfo(); resolveInfo.activityInfo = new ActivityInfo(); resolveInfo.activityInfo.packageName = "com.onesignal.example"; resolveInfo.activityInfo.name = "MainActivity"; RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(launchIntent, resolveInfo); }
From source file:com.android.mail.utils.NotificationActionUtils.java
/** * Creates a {@link PendingIntent} for the specified Wear notification action. *//*from w w w . ja v a 2s .c o m*/ private static PendingIntent getWearNotificationActionPendingIntent(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, NotificationAction.SOURCE_REMOTE, notificationId); switch (action) { case REPLY: 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, (action == NotificationActionType.REPLY_ALL)); intent.setPackage(context.getPackageName()); intent.setData(buildWearUri(conversation.uri)); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_FOLDER, folder); intent.putExtra(ComposeActivity.EXTRA_NOTIFICATION_CONVERSATION, conversation.uri); taskStackBuilder.addNextIntent(notificationIntent).addNextIntent(intent); return taskStackBuilder.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT); } case ARCHIVE_REMOVE_LABEL: case DELETE: { final String intentAction = (action == NotificationActionType.ARCHIVE_REMOVE_LABEL) ? NotificationActionIntentService.ACTION_ARCHIVE_REMOVE_LABEL : NotificationActionIntentService.ACTION_DELETE; final Intent intent = new Intent(intentAction); intent.setPackage(context.getPackageName()); intent.setData(buildWearUri(conversation.uri)); putNotificationActionExtra(intent, notificationAction); return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); } } throw new IllegalArgumentException("Invalid NotificationActionType"); }
From source file:com.master.metehan.filtereagle.ActivityMain.java
private static Intent getIntentInvite(Context context) { Intent intent = new Intent("com.google.android.gms.appinvite.ACTION_APP_INVITE"); intent.setPackage("com.google.android.gms"); intent.putExtra("com.google.android.gms.appinvite.TITLE", context.getString(R.string.menu_invite)); intent.putExtra("com.google.android.gms.appinvite.MESSAGE", context.getString(R.string.msg_try)); intent.putExtra("com.google.android.gms.appinvite.BUTTON_TEXT", context.getString(R.string.msg_try)); // com.google.android.gms.appinvite.DEEP_LINK_URL return intent; }
From source file:com.farmerbb.taskbar.activity.ImportSettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.import_settings); setFinishOnTouchOutside(false);/*ww w . j a v a2s .co m*/ LocalBroadcastManager.getInstance(this).registerReceiver(settingsReceivedReceiver, new IntentFilter("com.farmerbb.taskbar.IMPORT_FINISHED")); if (!broadcastSent) { Intent intent = new Intent("com.farmerbb.taskbar.RECEIVE_SETTINGS"); intent.setPackage(BuildConfig.BASE_APPLICATION_ID); sendBroadcast(intent); broadcastSent = true; } }
From source file:com.lambdasoup.blockvote.base.comms.BlockvoteFirebaseMessagingService.java
private void process(Map<String, String> data) { String time = data.get("time"); String votes = data.get("votes"); try {/* www .j a v a 2 s .c o m*/ JSONObject jsonObject = new JSONObject(votes); JSONObject segwit = jsonObject.getJSONObject("segwit"); JSONObject unlimited = jsonObject.getJSONObject("unlimited"); ContentValues cvSegwit = fromJson(segwit, Id.SEGWIT.name(), time); ContentValues cvUnlimited = fromJson(unlimited, Id.UNLIMITED.name(), time); ContentValues[] contentValues = { cvSegwit, cvUnlimited }; getContentResolver().bulkInsert(StatsProvider.CONTENT_URI, contentValues); } catch (JSONException e) { throw new RuntimeException("could not parse FCM data: " + votes); } // tell service to update all widgets Intent intent = new Intent("com.lambdasoup.blockvote.UPDATE"); intent.setPackage(getPackageName()); startService(intent); }
From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver.java
public AlarmReceiver() { Context context = GBApplication.getContext(); Intent intent = new Intent("DAILY_ALARM"); intent.setPackage(BuildConfig.APPLICATION_ID); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, new Intent("DAILY_ALARM"), 0); AlarmManager am = (AlarmManager) (context.getSystemService(Context.ALARM_SERVICE)); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis() + 10000, AlarmManager.INTERVAL_DAY, pendingIntent); }
From source file:co.uk.gauntface.mobile.devicelab.receiver.PushNotificationReceiver.java
private void launchBrowserTask(Context context, String url, String packageName) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); browserIntent.setPackage(packageName); browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); List<ResolveInfo> activitiesList = context.getPackageManager().queryIntentActivities(browserIntent, -1); if (activitiesList.size() > 0) { context.startActivity(browserIntent); } else {// w w w.j a va 2s. c o m Intent playStoreIntent = new Intent(Intent.ACTION_VIEW); playStoreIntent.setData(Uri.parse("market://details?id=" + packageName)); playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(playStoreIntent); } }
From source file:it.mb.whatshare.SendToWhatsappActivity.java
private Intent createIntent(String message) { Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setPackage(MainActivity.WHATSAPP_PACKAGE); i.setType("text/plain"); i.putExtra(Intent.EXTRA_TEXT, message); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Log.d("main", "this is the message: " + message); return i;/* w ww.j av a 2 s . co m*/ }