List of usage examples for android.content Intent setPackage
public @NonNull Intent setPackage(@Nullable String packageName)
From source file:me.tb.player.SkeletonActivity.java
public void onShareClick() { Resources resources = getResources(); String type = "image/*"; String mediaPath = Environment.getExternalStorageDirectory() + "/game_icon1.png"; // Create the URI from the media File media = new File(mediaPath); Uri uri = Uri.fromFile(media);// w w w .j a va 2 s. com 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_TEXT, "Download in Google Play Store\nhttps://play.google.com/store/apps/details?id=me.tb.player"); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Play Word Bandit - Multiplayer"); emailIntent.putExtra(Intent.EXTRA_STREAM, uri); emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); emailIntent.setType(type); PackageManager pm = getPackageManager(); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType(type); 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("com.google.android.gm")) { emailIntent.setPackage(packageName); } else if (packageName.contains("twitter") || packageName.contains("facebook.katana") || packageName.contains("com.instagram.android")) { Intent intent = new Intent(); intent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); intent.setAction(Intent.ACTION_SEND); intent.setType(type); // Add the URI and the caption to the Intent. intent.putExtra(Intent.EXTRA_STREAM, uri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); if (packageName.contains("twitter") || packageName.contains("instagram")) { intent.putExtra(Intent.EXTRA_TEXT, shareMessageCombo + "\nDownload now https://play.google.com/store/apps/details?id=me.tb.player"); } intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon)); } } // convert intentList to array LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]); openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents); startActivity(openInChooser); }
From source file:org.getlantern.firetweet.util.Utils.java
public static void openMap(final Context context, final double latitude, final double longitude) { if (context == null || !ParcelableLocation.isValidLocation(latitude, longitude)) return;//from ww w .j a v a 2 s .c o m final Uri.Builder builder = new Uri.Builder(); builder.scheme(SCHEME_FIRETWEET); builder.authority(AUTHORITY_MAP); builder.appendQueryParameter(QUERY_PARAM_LAT, String.valueOf(latitude)); builder.appendQueryParameter(QUERY_PARAM_LNG, String.valueOf(longitude)); final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); intent.setPackage(context.getPackageName()); context.startActivity(Intent.createChooser(intent, null)); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String StrtUpdtOMatic(String sPkgName, String sPkgFileName, String sCallBackIP, String sCallBackPort) { String sRet = ""; Context ctx = contextWrapper.getApplicationContext(); PackageManager pm = ctx.getPackageManager(); Intent prgIntent = new Intent(); prgIntent.setPackage("com.mozilla.watcher"); try {//from ww w. j a v a 2 s . c o m PackageInfo pi = pm.getPackageInfo("com.mozilla.watcher", PackageManager.GET_SERVICES | PackageManager.GET_INTENT_FILTERS); ServiceInfo[] si = pi.services; for (int i = 0; i < si.length; i++) { ServiceInfo s = si[i]; if (s.name.length() > 0) { prgIntent.setClassName(s.packageName, s.name); break; } } } catch (NameNotFoundException e) { e.printStackTrace(); sRet = sErrorPrefix + "watcher is not properly installed"; return (sRet); } prgIntent.putExtra("command", "updt"); prgIntent.putExtra("pkgName", sPkgName); prgIntent.putExtra("pkgFile", sPkgFileName); prgIntent.putExtra("reboot", true); try { if ((sCallBackIP != null) && (sCallBackPort != null) && (sCallBackIP.length() > 0) && (sCallBackPort.length() > 0)) { FileOutputStream fos = ctx.openFileOutput("update.info", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE); String sBuffer = sCallBackIP + "," + sCallBackPort + "\rupdate started " + sPkgName + " " + sPkgFileName + "\r"; fos.write(sBuffer.getBytes()); fos.flush(); fos.close(); fos = null; prgIntent.putExtra("outFile", ctx.getFilesDir() + "/update.info"); } else { if (prgIntent.hasExtra("outFile")) { System.out.println("outFile extra unset from intent"); prgIntent.removeExtra("outFile"); } } ComponentName cn = contextWrapper.startService(prgIntent); if (cn != null) sRet = "exit"; else sRet = sErrorPrefix + "Unable to use watcher service"; } catch (ActivityNotFoundException anf) { sRet = sErrorPrefix + "Activity Not Found Exception [updt] call failed"; anf.printStackTrace(); } catch (FileNotFoundException e) { sRet = sErrorPrefix + "File creation error [updt] call failed"; e.printStackTrace(); } catch (IOException e) { sRet = sErrorPrefix + "File error [updt] call failed"; e.printStackTrace(); } ctx = null; return (sRet); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String StartJavaPrg(String[] sArgs, Intent preIntent) { String sRet = ""; String sArgList = ""; String sUrl = ""; // String sRedirFileName = ""; Intent prgIntent = null; Context ctx = contextWrapper.getApplicationContext(); PackageManager pm = ctx.getPackageManager(); if (preIntent == null) prgIntent = new Intent(); else//from w ww.ja v a2s . co m prgIntent = preIntent; prgIntent.setPackage(sArgs[0]); prgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Get the main activity for this package try { final ComponentName c = pm.getLaunchIntentForPackage(sArgs[0]).getComponent(); prgIntent.setClassName(c.getPackageName(), c.getClassName()); } catch (Exception e) { e.printStackTrace(); return "Unable to find main activity for package: " + sArgs[0]; } if (sArgs.length > 1) { if (sArgs[0].contains("android.browser")) prgIntent.setAction(Intent.ACTION_VIEW); else prgIntent.setAction(Intent.ACTION_MAIN); if (sArgs[0].contains("fennec") || sArgs[0].contains("firefox")) { sArgList = ""; sUrl = ""; for (int lcv = 1; lcv < sArgs.length; lcv++) { if (sArgs[lcv].contains("://")) { prgIntent.setAction(Intent.ACTION_VIEW); sUrl = sArgs[lcv]; } else { if (sArgs[lcv].equals(">")) { lcv++; if (lcv < sArgs.length) lcv++; // sRedirFileName = sArgs[lcv++]; } else sArgList += " " + sArgs[lcv]; } } if (sArgList.length() > 0) prgIntent.putExtra("args", sArgList.trim()); if (sUrl.length() > 0) prgIntent.setData(Uri.parse(sUrl.trim())); } else { for (int lcv = 1; lcv < sArgs.length; lcv++) sArgList += " " + sArgs[lcv]; prgIntent.setData(Uri.parse(sArgList.trim())); } } else { prgIntent.setAction(Intent.ACTION_MAIN); } try { contextWrapper.startActivity(prgIntent); FindProcThread findProcThrd = new FindProcThread(contextWrapper, sArgs[0]); findProcThrd.start(); findProcThrd.join(7000); if (!findProcThrd.bFoundIt && !findProcThrd.bStillRunning) { sRet = "Unable to start " + sArgs[0] + ""; } } catch (ActivityNotFoundException anf) { anf.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } ctx = null; return (sRet); }
From source file:com.android.launcher2.Launcher.java
private boolean updateVoiceSearchIcon(boolean searchVisible) { final View voiceButtonContainer = findViewById(R.id.voice_button_container); final View voiceButton = findViewById(R.id.voice_button); final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); // We only show/update the voice search icon if the search icon is enabled as well final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); ComponentName activityName = null;/*from w w w. j ava 2 s . co m*/ if (globalSearchActivity != null) { // Check if the global search activity handles voice search Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setPackage(globalSearchActivity.getPackageName()); activityName = intent.resolveActivity(getPackageManager()); } if (activityName == null) { // Fallback: check if an activity other than the global search activity // resolves this Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); activityName = intent.resolveActivity(getPackageManager()); } if (searchVisible && activityName != null) { int coi = getCurrentOrientationIndexForGlobalIcons(); sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); if (sVoiceSearchIcon[coi] == null) { sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_ICON_METADATA_NAME); } if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); voiceButton.setVisibility(View.VISIBLE); if (voiceButtonProxy != null) { voiceButtonProxy.setVisibility(View.VISIBLE); } invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); return true; } else { if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); voiceButton.setVisibility(View.GONE); if (voiceButtonProxy != null) { voiceButtonProxy.setVisibility(View.GONE); } return false; } }
From source file:com.android.launcher2.Launcher.java
/** * Event handler for the voice button//from w w w . ja v a 2s. c o m * * @param v The view that was clicked. */ public void onClickVoiceButton(View v) { v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); try { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName activityName = searchManager.getGlobalSearchActivity(); Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (activityName != null) { intent.setPackage(activityName.getPackageName()); } startActivity(null, intent, "onClickVoiceButton"); } catch (ActivityNotFoundException e) { Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivitySafely(null, intent, "onClickVoiceButton"); } }
From source file:com.android.mail.ui.AbstractActivityController.java
public void changeAccount(Account account) { LogUtils.d(LOG_TAG, "AAC.changeAccount(%s)", account); // Is the account or account settings different from the existing account? final boolean firstLoad = mAccount == null; final boolean accountChanged = firstLoad || !account.uri.equals(mAccount.uri); // If nothing has changed, return early without wasting any more time. if (!accountChanged && !account.settingsDiffer(mAccount)) { return;/*ww w. jav a2 s .c o m*/ } // We also don't want to do anything if the new account is null if (account == null) { LogUtils.e(LOG_TAG, "AAC.changeAccount(null) called."); return; } final String emailAddress = account.getEmailAddress(); mHandler.post(new Runnable() { @Override public void run() { MailActivity.setNfcMessage(emailAddress); } }); if (accountChanged) { commitDestructiveActions(false); } // Change the account here setAccount(account); // And carry out associated actions. cancelRefreshTask(); if (accountChanged) { loadAccountInbox(); } // Check if we need to force setting up an account before proceeding. if (mAccount != null && !Uri.EMPTY.equals(mAccount.settings.setupIntentUri)) { // Launch the intent! final Intent intent = new Intent(Intent.ACTION_EDIT); intent.setPackage(mContext.getPackageName()); intent.setData(mAccount.settings.setupIntentUri); mActivity.startActivity(intent); } }
From source file:com.android.mail.compose.ComposeActivity.java
private void finishCreate() { final Bundle savedState = mInnerSavedState; findViews();/*from w ww. j a v a 2s.c o m*/ final Intent intent = getIntent(); final Message message; final ArrayList<AttachmentPreview> previews; mShowQuotedText = false; final CharSequence quotedText; int action; // Check for any of the possibly supplied accounts.; final Account account; if (hadSavedInstanceStateMessage(savedState)) { action = savedState.getInt(EXTRA_ACTION, COMPOSE); account = savedState.getParcelable(Utils.EXTRA_ACCOUNT); message = savedState.getParcelable(EXTRA_MESSAGE); previews = savedState.getParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS); mRefMessage = savedState.getParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE); quotedText = savedState.getCharSequence(EXTRA_QUOTED_TEXT); mExtraValues = savedState.getParcelable(EXTRA_VALUES); // Get the draft id from the request id if there is one. if (savedState.containsKey(EXTRA_REQUEST_ID)) { final int requestId = savedState.getInt(EXTRA_REQUEST_ID); if (sRequestMessageIdMap.containsKey(requestId)) { synchronized (mDraftLock) { mDraftId = sRequestMessageIdMap.get(requestId); } } } } else { account = obtainAccount(intent); action = intent.getIntExtra(EXTRA_ACTION, COMPOSE); // Initialize the message from the message in the intent message = intent.getParcelableExtra(ORIGINAL_DRAFT_MESSAGE); previews = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENT_PREVIEWS); mRefMessage = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE); mRefMessageUri = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE_URI); quotedText = null; if (Analytics.isLoggable()) { if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) { Analytics.getInstance().sendEvent("notification_action", "compose", getActionString(action), 0); } } } mAttachmentsView.setAttachmentPreviews(previews); setAccount(account); if (mAccount == null) { return; } initRecipients(); // Clear the notification and mark the conversation as seen, if necessary final Folder notificationFolder = intent.getParcelableExtra(EXTRA_NOTIFICATION_FOLDER); if (notificationFolder != null) { final Uri conversationUri = intent.getParcelableExtra(EXTRA_NOTIFICATION_CONVERSATION); Intent actionIntent; if (conversationUri != null) { actionIntent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS_WEAR); actionIntent.putExtra(Utils.EXTRA_CONVERSATION, conversationUri); } else { actionIntent = new Intent(MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS); actionIntent.setData(Utils.appendVersionQueryParameter(this, notificationFolder.folderUri.fullUri)); } actionIntent.setPackage(getPackageName()); actionIntent.putExtra(Utils.EXTRA_ACCOUNT, account); actionIntent.putExtra(Utils.EXTRA_FOLDER, notificationFolder); startService(actionIntent); } if (intent.getBooleanExtra(EXTRA_FROM_EMAIL_TASK, false)) { mLaunchedFromEmail = true; } else if (Intent.ACTION_SEND.equals(intent.getAction())) { final Uri dataUri = intent.getData(); if (dataUri != null) { final String dataScheme = intent.getData().getScheme(); final String accountScheme = mAccount.composeIntentUri.getScheme(); mLaunchedFromEmail = TextUtils.equals(dataScheme, accountScheme); } } if (mRefMessageUri != null) { mShowQuotedText = true; mComposeMode = action; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); String wearReply = null; if (remoteInput != null) { LogUtils.d(LOG_TAG, "Got remote input from new api"); CharSequence input = remoteInput.getCharSequence(NotificationActionUtils.WEAR_REPLY_INPUT); if (input != null) { wearReply = input.toString(); } } else { // TODO: remove after legacy code has been removed. LogUtils.d(LOG_TAG, "No remote input from new api, falling back to compatibility mode"); ClipData clipData = intent.getClipData(); if (clipData != null && LEGACY_WEAR_EXTRA.equals(clipData.getDescription().getLabel())) { Bundle extras = clipData.getItemAt(0).getIntent().getExtras(); if (extras != null) { wearReply = extras.getString(NotificationActionUtils.WEAR_REPLY_INPUT); } } } if (!TextUtils.isEmpty(wearReply)) { createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, mComposeMode, wearReply).execute(); finish(); return; } else { LogUtils.w(LOG_TAG, "remote input string is null"); } } getLoaderManager().initLoader(INIT_DRAFT_USING_REFERENCE_MESSAGE, null, this); return; } else if (message != null && action != EDIT_DRAFT) { initFromDraftMessage(message); initQuotedTextFromRefMessage(mRefMessage, action); mShowQuotedText = message.appendRefMessageContent; // if we should be showing quoted text but mRefMessage is null // and we have some quotedText, display that if (mShowQuotedText && mRefMessage == null) { if (quotedText != null) { initQuotedText(quotedText, false /* shouldQuoteText */); } else if (mExtraValues != null) { initExtraValues(mExtraValues); return; } } } else if (action == EDIT_DRAFT) { if (message == null) { throw new IllegalStateException("Message must not be null to edit draft"); } initFromDraftMessage(message); // Update the action to the draft type of the previous draft switch (message.draftType) { case UIProvider.DraftType.REPLY: action = REPLY; break; case UIProvider.DraftType.REPLY_ALL: action = REPLY_ALL; break; case UIProvider.DraftType.FORWARD: action = FORWARD; break; case UIProvider.DraftType.COMPOSE: default: action = COMPOSE; break; } LogUtils.d(LOG_TAG, "Previous draft had action type: %d", action); mShowQuotedText = message.appendRefMessageContent; if (message.refMessageUri != null) { // If we're editing an existing draft that was in reference to an existing message, // still need to load that original message since we might need to refer to the // original sender and recipients if user switches "reply <-> reply-all". mRefMessageUri = message.refMessageUri; mComposeMode = action; getLoaderManager().initLoader(REFERENCE_MESSAGE_LOADER, null, this); return; } } else if ((action == REPLY || action == REPLY_ALL || action == FORWARD)) { if (mRefMessage != null) { initFromRefMessage(action); mShowQuotedText = true; } } else { if (initFromExtras(intent)) { return; } } mComposeMode = action; finishSetup(action, intent, savedState); }
From source file:com.android.soma.Launcher.java
protected boolean updateVoiceSearchIcon(boolean searchVisible) { final View voiceButtonContainer = findViewById(R.id.voice_button_container); final View voiceButton = findViewById(R.id.voice_button); // We only show/update the voice search icon if the search icon is enabled as well final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); ComponentName activityName = null;/*from www. j av a 2s. c o m*/ if (globalSearchActivity != null) { // Check if the global search activity handles voice search Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setPackage(globalSearchActivity.getPackageName()); activityName = intent.resolveActivity(getPackageManager()); } if (activityName == null) { // Fallback: check if an activity other than the global search activity // resolves this Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); activityName = intent.resolveActivity(getPackageManager()); } if (searchVisible && activityName != null) { int coi = getCurrentOrientationIndexForGlobalIcons(); sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); if (sVoiceSearchIcon[coi] == null) { sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, TOOLBAR_ICON_METADATA_NAME); } if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); voiceButton.setVisibility(View.VISIBLE); updateVoiceButtonProxyVisible(false); invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); return true; } else { if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); if (voiceButton != null) voiceButton.setVisibility(View.GONE); updateVoiceButtonProxyVisible(false); return false; } }
From source file:com.android.soma.Launcher.java
public void startVoice() { try {/*from www. j a va 2 s .c o m*/ final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName activityName = searchManager.getGlobalSearchActivity(); Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (activityName != null) { intent.setPackage(activityName.getPackageName()); } startActivity(null, intent, "onClickVoiceButton"); } catch (ActivityNotFoundException e) { Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivitySafely(null, intent, "onClickVoiceButton"); } }