public void setPhotoAs() { if (!(albumItem instanceof Photo)) { return; } Uri uri = albumItem.getUri(this); Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); intent.setDataAndType(uri, MediaType.getMimeType(this, uri)); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { startActivityForResult(Intent.createChooser(intent, getString(R.string.set_as)), 13); } catch (SecurityException se) { Toast.makeText(this, "Error (SecurityException)", Toast.LENGTH_SHORT).show(); se.printStackTrace(); } catch (ActivityNotFoundException anfe) { Toast.makeText(this, "No App found", Toast.LENGTH_SHORT).show(); anfe.printStackTrace(); } }
/** * 发送邮件 * * @param context * @param subject 主题 * @param content 内容 * @param emails 邮件地址 */ public static void sendEmail(Context context, String subject, String content, String... emails) { try { Intent intent = new Intent(Intent.ACTION_SEND); // 模拟器 // intent.setType("text/plain"); intent.setType("message/rfc822"); // 真机 intent.putExtra(Intent.EXTRA_EMAIL, emails); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, content); context.startActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
private ActivityResult realExecStartActivity( Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) { ActivityResult result = null; try { Class[] parameterTypes = {Context.class, IBinder.class, IBinder.class, Activity.class, Intent.class, int.class, Bundle.class}; result = (ActivityResult)ReflectUtil.invoke(Instrumentation.class, mBase, "execStartActivity", parameterTypes, who, contextThread, token, target, intent, requestCode, options); } catch (Exception e) { if (e.getCause() instanceof ActivityNotFoundException) { throw (ActivityNotFoundException) e.getCause(); } e.printStackTrace(); } return result; }
private void startCameraIntent(final Activity activity, final Fragment fragment, String subFolder, final String action, final int requestCode) { final String cameraOutDir = BoxingFileHelper.getExternalDCIM(subFolder); try { if (BoxingFileHelper.createFile(cameraOutDir)) { mOutputFile = new File(cameraOutDir, String.valueOf(System.currentTimeMillis()) + ".jpg"); mSourceFilePath = mOutputFile.getPath(); Intent intent = new Intent(action); Uri uri = getFileUri(activity.getApplicationContext(), mOutputFile); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); try { startActivityForResult(activity, fragment, intent, requestCode); } catch (ActivityNotFoundException ignore) { callbackError(); } } } catch (ExecutionException | InterruptedException e) { BoxingLog.d("create file" + cameraOutDir + " error."); } }
private boolean tryFacebookActivity( StartActivityDelegate startActivityDelegate, LoginClient.Request request) { Intent intent = getFacebookActivityIntent(request); if (!resolveIntent(intent)) { return false; } try { startActivityDelegate.startActivityForResult( intent, LoginClient.getLoginRequestCode()); } catch (ActivityNotFoundException e) { return false; } return true; }
public boolean startActivitySafely(View v, Intent intent, ItemInfo item) { if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); return false; } // Only launch using the new animation if the shortcut has not opted out (this is a // private contract between launcher and may be ignored in the future). boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null; UserHandle user = item == null ? null : item.user; // Prepare intent intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (v != null) { intent.setSourceBounds(getViewBounds(v)); } try { if (AndroidVersion.isAtLeastMarshmallow && (item instanceof ShortcutInfo) && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) && !((ShortcutInfo) item).isPromise()) { // Shortcuts need some special checks due to legacy reasons. startShortcutIntentSafely(intent, optsBundle, item); } else if (user == null || user.equals(Process.myUserHandle())) { // Could be launching some bookkeeping activity startActivity(intent, optsBundle); } else { LauncherAppsCompat.getInstance(this).startActivityForProfile( intent.getComponent(), user, intent.getSourceBounds(), optsBundle); } return true; } catch (ActivityNotFoundException|SecurityException e) { Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); e.printStackTrace(); } return false; }
private static void openFile(Activity activity, File file, String string, View view) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", file); intent.setDataAndType(contentUri,string); } else { intent.setDataAndType(Uri.fromFile(file),string); } try { activity.startActivity (intent); } catch (ActivityNotFoundException e) { Snackbar.make(view, R.string.toast_install_app, Snackbar.LENGTH_LONG).show(); } }
@Override public void onDocumentPicked(DocumentInfo doc) { final FragmentManager fm = getFragmentManager(); if (doc.isDirectory()) { mState.stack.push(doc); mState.stackTouched = true; onCurrentDirectoryChanged(ANIM_DOWN); } else { // Fall back to viewing final Intent view = new Intent(Intent.ACTION_VIEW); view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); view.setData(doc.derivedUri); try { startActivity(view); } catch (ActivityNotFoundException ex2) { Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show(); } } }
public static void startGoogleSearchActivity(View view) { final Context context = view.getContext(); final SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); if (searchManager == null) { return; } ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); if (globalSearchActivity == null) { return; } Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(globalSearchActivity); Bundle appSearchData = new Bundle(); appSearchData.putString("source", context.getPackageName()); intent.putExtra(SearchManager.APP_DATA, appSearchData); intent.setSourceBounds(getViewBounds(view)); try { context.startActivity(intent); } catch (ActivityNotFoundException ex) { ex.printStackTrace(); } }
private void handleLocalApp() { final ComponentName component = new ComponentName(activity, SendCoinsActivity.class); final PackageManager pm = activity.getPackageManager(); final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(determineBitcoinRequestStr(false))); try { // launch intent chooser with ourselves excluded pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); startActivity(intent); } catch (final ActivityNotFoundException x) { new Toast(activity).longToast(R.string.request_coins_no_local_app_msg); } finally { pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); } activity.finish(); }
public static void gotoWchat(Activity activity) { try { Intent intent = new Intent(Intent.ACTION_MAIN); ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI"); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(cmp); activity.startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(activity, "检查到您手机没有安装微信,请安装后使用该功能", Toast.LENGTH_LONG).show(); } }
public static void shareText(Context context, String content, String hint) { if (context == null || TextUtils.isEmpty(content)) { return; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, content); try { if (TextUtils.isEmpty(hint)) { context.startActivity(intent); } else { context.startActivity(Intent.createChooser(intent, hint)); } } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
/** * Handles a click on the update menu item. * @param activity The current {@link ChromeActivity}. */ public void onMenuItemClicked(ChromeActivity activity) { if (mUpdateUrl == null) return; // If the update menu item is showing because it was forced on through about://flags // then mLatestVersion may be null. if (mLatestVersion != null) { PrefServiceBridge.getInstance().setLatestVersionWhenClickedUpdateMenuItem( mLatestVersion); } // Fire an intent to open the URL. try { Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUpdateUrl)); activity.startActivity(launchIntent); recordItemClickedHistogram(ITEM_CLICKED_INTENT_LAUNCHED); PrefServiceBridge.getInstance().setClickedUpdateMenuItem(true); } catch (ActivityNotFoundException e) { Log.e(TAG, "Failed to launch Activity for: %s", mUpdateUrl); recordItemClickedHistogram(ITEM_CLICKED_INTENT_FAILED); } }
@Override public boolean onTargetNotFound( @NonNull Context context, @NonNull Uri uri, @NonNull Bundle bundle, @Nullable Integer intentFlags) { Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtras(bundle); if (intentFlags != null) { intent.setFlags(intentFlags); } try { context.startActivity(intent); } catch (ActivityNotFoundException exception) { exception.printStackTrace(); return false; } return true; }
/** * qq咨询 */ public static boolean chatQQ(Context context, String qq) { try { if (CmdUtil.checkApkExist(context, "com.tencent.mobileqq")) { String url = "mqqwpa://im/chat?chat_type=wpa&uin=" + qq; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; } else { T_.error("您没有安装腾讯QQ"); } } catch (ActivityNotFoundException e) { e.printStackTrace(); T_.error("您没有安装腾讯QQ"); } return false; }
private void downloadFile(ResponseBody body) throws IOException { int count; byte data[] = new byte[1024 * 4]; InputStream bis = new BufferedInputStream(body.byteStream(), 1024 * 8); outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "file.zip"); OutputStream output = new FileOutputStream(outputFile); while ((count = bis.read(data)) != -1) { output.write(data, 0, count); } output.flush(); output.close(); bis.close(); Intent target = new Intent(Intent.ACTION_VIEW); target.setDataAndType(Uri.fromFile(outputFile), "application/pdf"); target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Intent intent = Intent.createChooser(target, "Open File"); try { startActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
public static void onShareClick(Context context, String message, String appName) { Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); // message might be in html form, so convert back to plain text message = Html.fromHtml(message).toString(); sendIntent.putExtra(Intent.EXTRA_TEXT, message); if(!appName.isEmpty()) sendIntent.setPackage(appName); try { context.startActivity(sendIntent); } catch(ActivityNotFoundException e){ Log.e("Social Share", "package does not exist"); Toast.makeText(context, "Action not supported",Toast.LENGTH_SHORT).show(); } }
/** * Begins a barcode scan, using the camera. When the scan is complete, the * AfterScan event will be raised. */ @SimpleFunction(description = "Begins a barcode scan, using the camera. When the scan " + "is complete, the AfterScan event will be raised.") public void DoScan() { Intent intent = new Intent(SCAN_INTENT); if (!useExternalScanner && (SdkLevel.getLevel() >= SdkLevel.LEVEL_ECLAIR)) { // Should we attempt to use an internal scanner? String packageName = container.$form().getPackageName(); intent.setComponent(new ComponentName(packageName, "com.google.zxing.client.android.AppInvCaptureActivity")); } if (requestCode == 0) { requestCode = form.registerForActivityResult(this); } try { container.$context().startActivityForResult(intent, requestCode); } catch (ActivityNotFoundException e) { e.printStackTrace(); container.$form().dispatchErrorOccurredEvent(this, "BarcodeScanner", ErrorMessages.ERROR_NO_SCANNER_FOUND, ""); } }
@OnClick(R.id.btnSpeak) public void onSpeakButtonClick() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.speech_prompt)); try { startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); } catch (ActivityNotFoundException a) { Toast.makeText(getApplicationContext(), getString(R.string.speech_not_supported), Toast.LENGTH_SHORT).show(); } }
private void openFileOnDevice(Uri mostRecentDownload) { Intent fileIntent = new Intent(Intent.ACTION_VIEW); // DownloadManager stores the Mime Type. Makes it really easy for us. String mimeType = mDownloadManager.getMimeTypeForDownloadedFile(fileDownloadId); fileIntent.setDataAndType(mostRecentDownload, mimeType); fileIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { mContext.startActivity(fileIntent); } catch (ActivityNotFoundException e) { Log.d("ficsaveM/cantOpenFile", fileName); trackFileCannotOpen(); Toast.makeText(mContext, "You don't have a supported ebook reader", Toast.LENGTH_LONG).show(); } }
/** * Showing google speech input dialog */ private void promptSpeechInput() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.speech_prompt)); try { startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); } catch (ActivityNotFoundException a) { Toast.makeText(getApplicationContext(), getString(R.string.speech_not_supported), Toast.LENGTH_SHORT).show(); } }
public static void openApplication(Activity context, String appURI, String webURI) { try { context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(appURI))); } catch (ActivityNotFoundException e1) { try { openHTMLPage(context, webURI); } catch (ActivityNotFoundException e2) { Toast.makeText(context, R.string.egab_can_not_open, Toast.LENGTH_SHORT).show(); } } }
public static boolean browse(Context context, String link) { try { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return true; } catch (ActivityNotFoundException ignored) { return false; } }
/** * API19 之前选择视频 */ protected void chooseVideoFromLocalBeforeKitKat() { Intent mIntent = new Intent(Intent.ACTION_GET_CONTENT); mIntent.setType(C.MimeType.MIME_VIDEO_ALL); mIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); try { activity.startActivityForResult(mIntent, localRequestCode); } catch (ActivityNotFoundException e) { Toast.makeText(activity, R.string.gallery_invalid, Toast.LENGTH_SHORT).show(); } }
private void startActivityToCropImage() { mIntentBuilder.outputUri(mUri); Intent intent = mIntentBuilder.buildCropApp(); try { startActivityForResult(intent, REQ_CODE_CROP_AVATAR); } catch (ActivityNotFoundException e) { showToastMsg("Your device is not support to crop image."); } }
final void openURL(String url) { // Strangely, some Android browsers don't seem to register to handle HTTP:// or HTTPS://. // Lower-case these as it should always be OK to lower-case these schemes. if (url.startsWith("HTTP://")) { url = "http" + url.substring(4); } else if (url.startsWith("HTTPS://")) { url = "https" + url.substring(5); } Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); try { launchIntent(intent); } catch (ActivityNotFoundException ignored) { Log.w(TAG, "Nothing available to handle " + intent); } }
public static void launchEmail(@NonNull Context context, @NonNull String email){ Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email}); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try{ context.startActivity(Intent.createChooser(intent, context.getString(R.string.send_email))); }catch (ActivityNotFoundException e){ Toasty.warning(context, context.getString(R.string.no_email_clients)).show(); } }
/** * 获取本地图片 */ protected void choosePictureFromLocal() { if (!StorageUtil.hasEnoughSpaceForWrite(PreviewImageFromCameraActivity.this, StorageType.TYPE_IMAGE, true)) { return; } new AsyncTask<String, Integer, Boolean>() { @Override protected void onPreExecute() { Toast.makeText(PreviewImageFromCameraActivity.this, R.string.waitfor_image_local, Toast.LENGTH_LONG).show(); } @Override protected Boolean doInBackground(String... params) { return true; } @Override protected void onPostExecute(Boolean result) { Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); if (Build.VERSION.SDK_INT >= 11) { intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); } try { PreviewImageFromCameraActivity.this.startActivityForResult(intent, RequestCode.GET_LOCAL_IMAGE); } catch (ActivityNotFoundException e) { Toast.makeText(PreviewImageFromCameraActivity.this, R.string.gallery_invalid, Toast.LENGTH_LONG).show(); } } }.execute(); }
@Override public boolean openUI(Context context) { try { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.setComponent(mName); mContext.startActivity(intent); } catch (ActivityNotFoundException e) { } return true; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSpinnerFragment = new SpinnerFragment(); mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); mVideoCursorAdapter.setMapper(new VideoCursorMapper()); setSearchResultProvider(this); setOnItemViewClickedListener(new ItemViewClickedListener()); if (DEBUG) { Log.d(TAG, "User is initiating a search. Do we have RECORD_AUDIO permission? " + hasPermission(Manifest.permission.RECORD_AUDIO)); } if (!hasPermission(Manifest.permission.RECORD_AUDIO)) { if (DEBUG) { Log.d(TAG, "Does not have RECORD_AUDIO, using SpeechRecognitionCallback"); } // SpeechRecognitionCallback is not required and if not provided recognition will be // handled using internal speech recognizer, in which case you must have RECORD_AUDIO // permission setSpeechRecognitionCallback(new SpeechRecognitionCallback() { @Override public void recognizeSpeech() { try { startActivityForResult(getRecognizerIntent(), REQUEST_SPEECH); } catch (ActivityNotFoundException e) { Log.e(TAG, "Cannot find activity for speech recognizer", e); } } }); } else if (DEBUG) { Log.d(TAG, "We DO have RECORD_AUDIO"); } }
private void share() { try { Intent shareIntent = new Intent(Intent.ACTION_SENDTO); shareIntent.setData(Uri.parse("mailto:")); shareIntent.putExtra(Intent.EXTRA_SUBJECT, " AndiCar - " + getTitle()); shareIntent.putExtra(Intent.EXTRA_TEXT, mEmailText_Filters.toString().replace("\t", " ") + "\n\n" + "Data:\n" + mEmailText_Values.toString().replace("\t", " ") + "\n\nSent by AndiCar (http://www.andicar.org)"); startActivity(shareIntent); } catch (ActivityNotFoundException e) { Utils.showNotReportableErrorDialog(this, e.getMessage(), null); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.mi_export_database: new DatabaseExportTask(this, mThreeThingsDatabase).execute(); return true; case R.id.mi_import_database: Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try { startActivityForResult(Intent.createChooser(intent, "Select a file to open"), DATABASE_IMPORT_CODE); } catch (ActivityNotFoundException e) { Toast.makeText(getApplicationContext(), "Please install a File Manager", Toast.LENGTH_LONG).show(); } return true; case R.id.mi_sign_in_sign_out: if (FirebaseAuth.getInstance().getCurrentUser() == null) { Intent signInIntent = AuthUI.getInstance().createSignInIntentBuilder() .setProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build())) .build(); startActivityForResult(signInIntent, FIREBASE_SIGN_IN_CODE); } else { FirebaseAuth.getInstance().signOut(); Toast.makeText(this, "Signed out", Toast.LENGTH_SHORT).show(); } return true; case R.id.mi_test_notification: Intent notificationIntent = new Intent(this, NotificationIntentService.class); startService(notificationIntent); return true; default: return super.onOptionsItemSelected(item); } }
void safeStartActivity(Intent intent) { try { this.context.startActivity(intent); } catch (ActivityNotFoundException e) { Log.d(TAG, "Failed to start activity"); } }
private void openUrl(String url) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }
@Test public void createIntentWithOldSwedbankAppThrows() { try { installApp("com.swedbank", 1, SWEDBANK_SIGNATURE); final Intent banklinkIntent = eeClient.createBanklinkIntent(SIGNED_PACKET_MAP); fail(); } catch (ActivityNotFoundException e) { assertThat(e.getMessage()).isEqualTo("Swedbank app is not installed on this device."); } }
private void handleAddToContacts() { try { final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipients.getPrimaryRecipient().getNumber()); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); startActivityForResult(intent, ADD_CONTACT); } catch (ActivityNotFoundException e) { Log.w(TAG, e); } }