List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.java
private boolean startNotificationService() { if (!isFeatureEnabled(FEATURE_NOTIFICATION)) { return true; }//w w w. jav a2 s. co m LOGD(TAG, "startNotificationService()"); Intent service = new Intent(mContext, VideoCastNotificationService.class); service.setPackage(mContext.getPackageName()); service.setAction(VideoCastNotificationService.ACTION_VISIBILITY); service.putExtra(VideoCastNotificationService.NOTIFICATION_VISIBILITY, !mUiVisible); return mContext.startService(service) != null; }
From source file:org.cloudsky.cordovaPlugins.BarcodeminCDV.java
/** * Starts an intent to scan and decode a barcode. *///from w w w.java 2 s . c o m public void scan(final JSONArray args) { final CordovaPlugin that = this; cordova.getThreadPool().execute(new Runnable() { public void run() { Intent intentScan = new Intent(SCAN_INTENT); intentScan.addCategory(Intent.CATEGORY_DEFAULT); // add config as intent extras if (args.length() > 0) { JSONObject obj; JSONArray names; String key; Object value; for (int i = 0; i < args.length(); i++) { try { obj = args.getJSONObject(i); } catch (JSONException e) { Log.i("CordovaLog", e.getLocalizedMessage()); continue; } names = obj.names(); for (int j = 0; j < names.length(); j++) { try { key = names.getString(j); value = obj.get(key); if (value instanceof Integer) { intentScan.putExtra(key, (Integer) value); } else if (value instanceof String) { intentScan.putExtra(key, (String) value); } } catch (JSONException e) { Log.i("CordovaLog", e.getLocalizedMessage()); } } intentScan.putExtra(Intents.Scan.CAMERA_ID, obj.optBoolean(PREFER_FRONTCAMERA, false) ? 1 : 0); intentScan.putExtra(Intents.Scan.SHOW_FLIP_CAMERA_BUTTON, obj.optBoolean(SHOW_FLIP_CAMERA_BUTTON, false)); if (obj.has(FORMATS)) { intentScan.putExtra(Intents.Scan.FORMATS, obj.optString(FORMATS)); } if (obj.has(PROMPT)) { intentScan.putExtra(Intents.Scan.PROMPT_MESSAGE, obj.optString(PROMPT)); } //if (obj.has(ORIENTATION)) { //intentScan.putExtra(Intents.Scan.ORIENTATION_LOCK, obj.optString(ORIENTATION)); intentScan.putExtra(Intents.Scan.ORIENTATION_LOCK, "false"); //} } } // avoid calling other phonegap apps intentScan.setPackage(that.cordova.getActivity().getApplicationContext().getPackageName()); that.cordova.startActivityForResult(that, intentScan, REQUEST_CODE); } }); }
From source file:com.farmerbb.taskbar.fragment.FreeformModeFragment.java
@TargetApi(Build.VERSION_CODES.N) @Override/*ww w .jav a 2s . c o m*/ public boolean onPreferenceClick(final Preference p) { final SharedPreferences pref = U.getSharedPreferences(getActivity()); switch (p.getKey()) { case "freeform_hack": if (((CheckBoxPreference) p).isChecked()) { if (!U.hasFreeformSupport(getActivity())) { ((CheckBoxPreference) p).setChecked(false); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.freeform_dialog_title).setMessage(R.string.freeform_dialog_message) .setPositiveButton(R.string.action_developer_options, (dialogInterface, i) -> { showReminderToast = true; Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); try { startActivity(intent); U.showToastLong(getActivity(), R.string.enable_force_activities_resizable); } catch (ActivityNotFoundException e) { intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS); try { startActivity(intent); U.showToastLong(getActivity(), R.string.enable_developer_options); } catch (ActivityNotFoundException e2) { /* Gracefully fail */ } } }); AlertDialog dialog = builder.create(); dialog.show(); dialog.setCancelable(false); } if (pref.getBoolean("taskbar_active", false) && getActivity().isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) { U.startFreeformHack(getActivity(), false, false); } } else { LocalBroadcastManager.getInstance(getActivity()) .sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY")); LocalBroadcastManager.getInstance(getActivity()) .sendBroadcast(new Intent("com.farmerbb.taskbar.FORCE_TASKBAR_RESTART")); } break; case "freeform_mode_help": AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setView(View.inflate(getActivity(), R.layout.freeform_help_dialog, null)) .setTitle(R.string.freeform_help_dialog_title).setPositiveButton(R.string.action_close, null); AlertDialog dialog = builder.create(); dialog.show(); break; case "add_shortcut": Intent intent = U.getShortcutIntent(getActivity()); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); intent.putExtra("duplicate", false); Intent homeIntent = new Intent(Intent.ACTION_MAIN); homeIntent.addCategory(Intent.CATEGORY_HOME); ResolveInfo defaultLauncher = getActivity().getPackageManager().resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY); intent.setPackage(defaultLauncher.activityInfo.packageName); getActivity().sendBroadcast(intent); U.showToast(getActivity(), R.string.shortcut_created); break; case "window_size": if (U.isOPreview()) { U.showToast(getActivity(), R.string.window_sizes_not_available); } break; } return true; }
From source file:com.android.mail.compose.ComposeActivity.java
private static Intent createActionIntent(final Context context, final Account account, final Uri messageUri, final int action) { final Intent intent = new Intent(ACTION_LAUNCH_COMPOSE); intent.setPackage(context.getPackageName()); updateActionIntent(account, messageUri, action, intent); return intent; }
From source file:com.android.mail.compose.ComposeActivity.java
public static void composeMailto(Context context, Account account, Uri mailto) { final Intent intent = new Intent(Intent.ACTION_VIEW, mailto); intent.setPackage(context.getPackageName()); intent.putExtra(EXTRA_FROM_EMAIL_TASK, true); intent.putExtra(Utils.EXTRA_ACCOUNT, account); if (mailto != null) { intent.setData(Utils.normalizeUri(mailto)); }/*from ww w . j a v a2 s. c o m*/ context.startActivity(intent); }
From source file:com.android.mail.compose.ComposeActivity.java
private static void launch(Context context, Account account, Message message, int action, String toAddress, String body, String quotedText, String subject, final ContentValues extraValues) { Intent intent = new Intent(ACTION_LAUNCH_COMPOSE); intent.setPackage(context.getPackageName()); intent.putExtra(EXTRA_FROM_EMAIL_TASK, true); intent.putExtra(EXTRA_ACTION, action); intent.putExtra(Utils.EXTRA_ACCOUNT, account); if (action == EDIT_DRAFT) { intent.putExtra(ORIGINAL_DRAFT_MESSAGE, message); } else {/*w w w .jav a 2s .co m*/ intent.putExtra(EXTRA_IN_REFERENCE_TO_MESSAGE, message); } if (toAddress != null) { intent.putExtra(EXTRA_TO, toAddress); } if (body != null) { intent.putExtra(EXTRA_BODY, body); } if (quotedText != null) { intent.putExtra(EXTRA_QUOTED_TEXT, quotedText); } if (subject != null) { intent.putExtra(EXTRA_SUBJECT, subject); } if (extraValues != null) { LogUtils.d(LOG_TAG, "Launching with extraValues: %s", extraValues.toString()); intent.putExtra(EXTRA_VALUES, extraValues); } if (action == COMPOSE) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } else if (message != null) { intent.setData(Utils.normalizeUri(message.uri)); } context.startActivity(intent); }
From source file:me.tb.player.SkeletonActivity.java
private void initShareIntent(String type) { boolean found = false; Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("image/jpeg"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0); if (!resInfo.isEmpty()) { for (ResolveInfo info : resInfo) { Log.d("package name", info.activityInfo.packageName.toLowerCase()); if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type)) { share.putExtra(Intent.EXTRA_SUBJECT, "subject"); share.putExtra(Intent.EXTRA_TEXT, "your text"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/game_icon1.png"))); // Optional, just if you wanna share an image. share.setPackage(info.activityInfo.packageName); found = true;//from ww w. jav a 2 s . c o m break; } } if (!found) return; startActivity(Intent.createChooser(share, "Select")); } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Allows to create a share intent and it can be launched. * /*ww w . j a v a 2s. c om*/ * @param context * @param type Mime type. * @param nameApp You can filter the application you want to share with. Use "wha", "twitt", etc. * @param title The title of the share.Take in account that sometimes is not possible to add the title. * @param data The data, can be a file or a text. * @param isBinaryData If the share has a data file, set to TRUE otherwise FALSE. */ @SuppressLint("DefaultLocale") public static Intent share_newSharingIntent(Context context, String type, String nameApp, String title, String data, boolean isBinaryData, boolean launch) { Intent res = null; Intent share = new Intent(Intent.ACTION_SEND); share.setType(type); List<Intent> targetedShareIntents = new ArrayList<Intent>(); List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(share, 0); if (!resInfo.isEmpty()) { for (ResolveInfo info : resInfo) { Intent targetedShare = new Intent(Intent.ACTION_SEND); targetedShare.setType(type); if (title != null) { targetedShare.putExtra(Intent.EXTRA_SUBJECT, title); targetedShare.putExtra(Intent.EXTRA_TITLE, title); if (data != null && !isBinaryData) { targetedShare.putExtra(Intent.EXTRA_TEXT, data); } } if (data != null && isBinaryData) { targetedShare.putExtra(Intent.EXTRA_TEXT, title); targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(data))); } if (nameApp != null) { if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) { targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } else { targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); res = chooserIntent; if (launch) { context.startActivity(chooserIntent); } } return res; }
From source file:com.aliyun.homeshell.Folder.java
public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, boolean success) { mDropAccepted = success;//from w w w .ja va2s. c o m Log.d(TAG, "sxsexe---------> onDropCompleted dragInfo " + d.dragInfo + " success " + success + " mDeleteFolderOnDropCompleted " + mDeleteFolderOnDropCompleted + " mItemAddedBackToSelfViaIcon " + mItemAddedBackToSelfViaIcon + " item count " + getItemCount() + " mHasDirtyData " + mHasDirtyData); /*YUNOS BEGIN*/ //##module(component name) //##date:2014/03/28 ##author:jun.dongj@alibaba-inc.com##BugID:105531 //there is a cellayout outline when drag icon in folder, otherwise, hide it showDragOutline(false); /*YUNOS END*/ mShortcutInfoCache = (ShortcutInfo) d.dragInfo; mLauncher.setCurrentFolder(this); if (success) { if (target instanceof DeleteDropTarget && mShortcutInfoCache.itemType == Favorites.ITEM_TYPE_APPLICATION) { /* YUNOS BEGIN PB*/ //##modules(HomeShell): ##author:guoshuai.lgs //##BugID:(5221896) ##date:2014/09/03 //##decrpition: support mainmenu feature, cancel drop feature, page management feature, and so on if (!LauncherApplication.isMainmenuMode()) { //go to uninstall or remove, Log.d(TAG, "sxsexe---------> onDropCompleted do not need to replaceFolderWithFinalItem"); mHasDirtyData = true; /*YUNOS BEGIN*/ //##date:2014/01/18 ##author:hao.liuhaolh ##BugID:83464 //app icon remove issue in folder if ((mShortcutInfoCache.intent != null) && (mShortcutInfoCache.intent.getComponent() != null) && (mShortcutInfoCache.intent.getComponent().getPackageName() != null)) { boolean storgeMount = Environment.getExternalStorageState() .equals(Environment.MEDIA_MOUNTED); String packageName = mShortcutInfoCache.intent.getComponent().getPackageName(); final PackageManager packageManager = ((Context) mLauncher).getPackageManager(); final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); mainIntent.setPackage(packageName); final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0); if ((apps == null || apps.size() == 0) && (storgeMount == true)) { Log.d(TAG, "no app info, so it need to be cleaned"); mHasDirtyData = false; } } } /*YUNOS END PB*/ /*YUNOS END*/ } /*YUNOS BEGIN*/ //##date:2014/7/2 ##author:yangshan.ys##BugID:134407 //if the target is workspace or hotseat when drag or fling icon ,call this method mDeleteFolderOnDropCompleted = mInfo.count() <= 1; if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && !(target instanceof DeleteDropTarget)) { /*YUNOS END*/ if (!mHasDirtyData) { //drag to workspace or hotseat replaceFolderWithFinalItem(); this.setNeedReplaceFolderWithFinalItemFlase(); } } } else { Log.d(TAG, "sxsexe---------> onDropCompleted drag failed need to get the item back "); /*YUNOS BEGIN*/ //##date:2014/06/18 ##author:guoshuai.lgs ##BugID: //support the folder feature in mainmenu if (LauncherApplication.isMainmenuMode() && (mInfo.isMainmenuFolder())) { // Exit spring loaded mode if we have not successfully dropped or have not handled the // drop in Workspace //Delete the dragview d.deferDragViewCleanupPostAnimation = false; mLauncher.exitSpringLoadedDragMode(); } else { // The drag failed, we need to return the item to the folder mFolderIcon.onDrop(d); } /*YUNOS END*/ // We're going to trigger a "closeFolder" which may occur before this item has // been added back to the folder -- this could cause the folder to be deleted if (mOnExitAlarm.alarmPending()) { mSuppressFolderDeletion = true; } } if (target != this) { if (mOnExitAlarm.alarmPending()) { mOnExitAlarm.cancelAlarm(); completeDragExit(); } } mDeleteFolderOnDropCompleted = false; mDragInProgress = false; mItemAddedBackToSelfViaIcon = false; mCurrentDragInfo = null; mCurrentDragView = null; mSuppressOnAdd = false; /* YUNOS BEGIN */ // ##date:2014/07/04 ##author:yangshan.ys##BugID:135044 // prevent the position of editfoldericon moving in folder if (target == this && mInfo.isEditFolderInContents() && mEditFolderTempView != null) { int childId = mEditFolderTempView.getId(); CellLayout.LayoutParams params = (CellLayout.LayoutParams) mEditFolderTempView.getLayoutParams(); mContentList.get(mInfo.getmEditFolderShortcutInfo().screen).addViewToCellLayout(mEditFolderTempView, -1, childId, params, true); mEditFolderHidden = false; } /* YUNOS END */ // Reordering may have occured, and we need to save the new item locations. We do this once // at the end to prevent unnecessary database operations. /*YUNOS BEGIN*/ //##date:2014/06/10 ##author:guoshuai.lgs ##BugID: //support the folder feature in mainmenu if (mInfo.isMainmenuFolder() && (LauncherApplication.isMainmenuMode())) { // TODO: do nothing? } else { updateItemLocationsInDatabase(); } /*YUNOS END*/ mLauncher.getWorkspace().cleanDragInfoFromFolder(); mLauncher.getWorkspace().checkAndRemoveEmptyCell(); }
From source file:com.aimfire.gallery.GalleryActivity.java
/** * share only to certain apps. code based on "http://stackoverflow.com/questions/ * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different- * text-for/18980872#18980872"/*w ww .jav a 2s . co m*/ * * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/ * * in general, "deep linking" is supported by the apps below. Facebook, Wechat, * Telegram are exceptions. click on the link would bring users to the landing * page. * * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first * then paste the link */ private void shareMedia(Intent data) { /* * we log this as "share complete", but user can still cancel the share at this point, * and we wouldn't be able to know */ mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_SHARE_COMPLETE, null); Resources resources = getResources(); /* * get the resource id for the shared file */ String id = data.getStringExtra(MainConsts.EXTRA_ID_RESOURCE); /* * construct link */ String link = "https://" + resources.getString(R.string.app_domain) + "/?id=" + id + "&name=" + ((mPreviewName != null) ? mPreviewName : mMediaName); /* * message subject and text */ String emailSubject, emailText, twitterText; if (MediaScanner.isPhoto(mMediaPath)) { emailSubject = resources.getString(R.string.emailSubjectPhoto); emailText = resources.getString(R.string.emailBodyPhotoPrefix) + link; twitterText = resources.getString(R.string.emailBodyPhotoPrefix) + link + resources.getString(R.string.twitterHashtagPhoto) + resources.getString(R.string.app_hashtag); } else if (MediaScanner.is3dMovie(mMediaPath)) { emailSubject = resources.getString(R.string.emailSubjectVideo); emailText = resources.getString(R.string.emailBodyVideoPrefix) + link; twitterText = resources.getString(R.string.emailBodyVideoPrefix) + link + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag); } else //if(MediaScanner.is2dMovie(mMediaPath)) { emailSubject = resources.getString(R.string.emailSubjectVideo2d); emailText = resources.getString(R.string.emailBodyVideoPrefix2d) + link; twitterText = resources.getString(R.string.emailBodyVideoPrefix2d) + link + resources.getString(R.string.twitterHashtagVideo) + resources.getString(R.string.app_hashtag); } Intent emailIntent = new Intent(); emailIntent.setAction(Intent.ACTION_SEND); // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); emailIntent.putExtra(Intent.EXTRA_TEXT, emailText); //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native))); emailIntent.setType("message/rfc822"); PackageManager pm = getPackageManager(); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text)); List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0); List<LabeledIntent> intentList = new ArrayList<LabeledIntent>(); for (int i = 0; i < resInfo.size(); i++) { // Extract the label, append it, and repackage it in a LabeledIntent ResolveInfo ri = resInfo.get(i); String packageName = ri.activityInfo.packageName; if (packageName.contains("android.email")) { emailIntent.setPackage(packageName); } else if (packageName.contains("twitter") || packageName.contains("facebook") || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber") || packageName.contains("kik") || packageName.contains("sgiggle") || //tango packageName.contains("kakao") || packageName.contains("telegram") || packageName.contains("nimbuzz") || packageName.contains("hike") || packageName.contains("imoim") || packageName.contains("bbm") || packageName.contains("threema") || packageName.contains("mms") || packageName.contains("android.apps.messaging") || //google messenger packageName.contains("android.talk") || //google hangouts packageName.contains("android.gm")) { Intent intent = new Intent(); intent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); if (packageName.contains("twitter")) { intent.putExtra(Intent.EXTRA_TEXT, twitterText); } else if (packageName.contains("facebook")) { /* * the warning below is wrong! at least on GS5, Facebook client does take * our text, however it seems it takes only the first hyperlink in the * text. * * Warning: Facebook IGNORES our text. They say "These fields are intended * for users to express themselves. Pre-filling these fields erodes the * authenticity of the user voice." * One workaround is to use the Facebook SDK to post, but that doesn't * allow the user to choose how they want to share. We can also make a * custom landing page, and the link will show the <meta content ="..."> * text from that page with our link in Facebook. */ intent.putExtra(Intent.EXTRA_TEXT, link); } else if (packageName.contains("tencent.mm")) //wechat { /* * wechat appears to do this similar to Facebook */ intent.putExtra(Intent.EXTRA_TEXT, link); } else if (packageName.contains("android.gm")) { // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject); intent.putExtra(Intent.EXTRA_TEXT, emailText); //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail))); intent.setType("message/rfc822"); } else if (packageName.contains("android.apps.docs")) { /* * google drive - no reason to send link to it */ continue; } else { intent.putExtra(Intent.EXTRA_TEXT, emailText); } intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon)); } } /* * create "Copy Link To Clipboard" Intent */ Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class); clipboardIntent.setData(Uri.parse(link)); intentList.add(new LabeledIntent(clipboardIntent, getPackageName(), getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link)); // convert intentList to array LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]); openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents); startActivity(openInChooser); }