Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
private static Intent getServicePlayerActivityIntent(final Context context, final Class activityClass) { Intent intent = new Intent(context, activityClass); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } return intent; } /*//////////////////////////////////////////////////////////////////////////
@Override public Intent buildIntent() { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; } }
public void showSendFileScreen(@NonNull String archiveFilename) { File file = new File(archiveFilename); Uri fileUri = getUriForFile(activity, "org.isoron.uhabits", file); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("application/zip"); intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); activity.startActivity(intent); }
private void shareBitmap (Bitmap bitmap,String fileName) { try { File file = new File(getContext().getCacheDir(), fileName + ".png"); FileOutputStream fOut = new FileOutputStream(file); bitmap.compress(CompressFormat.PNG, 100, fOut); fOut.flush(); fOut.close(); file.setReadable(true, false); final Intent intent = new Intent( android.content.Intent.ACTION_SEND); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); intent.setType("image/png"); startActivity(intent); } catch (Exception e) { e.printStackTrace(); } }
Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_APP_CALCULATOR); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.endsWith(".mp4")) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(url), "video/*"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); view.getContext().startActivity(intent); // If we return true, onPageStarted, onPageFinished won't be called. } else if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url .startsWith("mms:") || url.startsWith("mmsto:")) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); view.getContext().startActivity(intent); return true; // If we return true, onPageStarted, onPageFinished won't be called. Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{mt.getTo()}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject()); emailIntent.putExtra(Intent.EXTRA_CC, mt.getCc()); emailIntent.putExtra(Intent.EXTRA_TEXT, mt.getBody());
public static Intent getInstallApkIntent(File file) { Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); return intent; }
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String) v.getTag(R.string.app_name)); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) v.getTag(R.drawable.ic_launcher)); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); PackageManager pm = v.getContext().getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { if ((app.activityInfo.name).startsWith("com.facebook.katana")) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.setComponent(name); v.getContext().startActivity(shareIntent); break; } }
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(OpenPdf.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); }
/** * 调用自带的音频播放器 * * @param context * @param path */ private static void openAudio(Context context, String path) { File f = new File(path); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(f), "audio/*");// "audio/mp3" context.startActivity(intent); }
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent);
@Override public void run() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("application/octet-stream"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享HAR文件"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/test.zip"))); startActivity(Intent.createChooser(intent, "share")); } };
public static PendingIntent createPendingIntent(Context context, String referenceKey) { setEnabledBlocking(context, DisplayLeakActivity.class, true); Intent intent = new Intent(context, DisplayLeakActivity.class); intent.putExtra(SHOW_LEAK_EXTRA, referenceKey); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); return PendingIntent.getActivity(context, 1, intent, FLAG_UPDATE_CURRENT); }
@Override public void onClick(View v) { Context context = view.getContext(); Intent myAppSettings = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + context.getPackageName())); myAppSettings.addCategory(Intent.CATEGORY_DEFAULT); myAppSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(myAppSettings); } };
Bundle appLinkExtras = AppLinks.getAppLinkExtras(originalIntent); Intent resultIntent = new Intent(); if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) { resultIntent.putExtra(EXTRA_PROTOCOL_VERSION, MessengerUtils.PROTOCOL_VERSION_20150314); String threadToken = appLinkExtras.getString(MessengerUtils.EXTRA_THREAD_TOKEN_KEY); resultIntent.putExtra(EXTRA_THREAD_TOKEN_KEY, threadToken); } else { throw new RuntimeException(); // Can't happen. resultIntent.setDataAndType(shareToMessengerParams.uri, shareToMessengerParams.mimeType); resultIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); resultIntent.putExtra(EXTRA_APP_ID, FacebookSdk.getApplicationId()); resultIntent.putExtra(EXTRA_METADATA, shareToMessengerParams.metaData); resultIntent.putExtra(EXTRA_EXTERNAL_URI, shareToMessengerParams.externalUri);