List of usage examples for android.content Intent setAction
public @NonNull Intent setAction(@Nullable String action)
From source file:Main.java
public static void installApk(Context context, File file) { Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.setType("application/vnd.android.package-archive"); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);/*ww w .ja v a2s. c o m*/ }
From source file:Main.java
public static ResolveInfo getDefaultBrowser(Context context) { PackageManager pm = context.getPackageManager(); Intent query = new Intent(); query.setAction(Intent.ACTION_VIEW); query.setData(Uri.parse("http://localhost")); ResolveInfo info = pm.resolveActivity(query, 0); if (info == null) { return info; }/*w w w. j ava 2s . co m*/ // Could be a Chooser if (info.activityInfo.packageName.equals("android")) { return null; } return info; }
From source file:Main.java
public static boolean isGooglePlayInstalled(Context ctx) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://search?q=foo")); PackageManager pm = ctx.getPackageManager(); List<ResolveInfo> list = pm.queryIntentActivities(intent, 0); if (list.size() > 0) { return true; } else {/*from ww w . j a v a2 s.c o m*/ return false; } }
From source file:Main.java
public static Intent getSendIntent(Context context, String title, String text) { if (TextUtils.isEmpty(text)) throw new IllegalArgumentException("text cannot be empty or null"); if (TextUtils.isEmpty(title)) throw new IllegalArgumentException("title cannot be empty or null"); Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, text); sendIntent.setType("text/plain"); return Intent.createChooser(sendIntent, title); }
From source file:Main.java
public static void callGoogleTranslateApps(Context context, String word, String toLang) { try {/*from ww w . j ava 2 s. co m*/ Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.putExtra("key_text_input", word); i.putExtra("key_text_output", ""); i.putExtra("key_language_from", "en"); i.putExtra("key_language_to", "vi"); i.putExtra("key_suggest_translation", ""); i.putExtra("key_from_floating_window", false); i.setComponent(new ComponentName("com.google.android.apps.translate", "com.google.android.apps.translate.TranslateActivity")); context.startActivity(i); } catch (ActivityNotFoundException ex) { Toast.makeText(context, "Google translate app is not installed", Toast.LENGTH_SHORT).show(); ex.printStackTrace(); } }
From source file:Main.java
public static void startSelectLocalPhotoActivity(Activity activity, int requestCode) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); activity.startActivityForResult(intent, requestCode); }
From source file:Main.java
public static void openAlbum(Activity activity) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); activity.startActivityForResult(intent, PICK_IMAGE_ACTIVITY_REQUEST_CODE); }
From source file:Main.java
public static void pickPhoto(Activity activity, int resultCode) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); activity.startActivityForResult(intent, resultCode); }
From source file:Main.java
public static void pickVideo(Activity activity, int resultCode) { Intent intent = new Intent(); intent.setType("video/*"); intent.setAction(Intent.ACTION_GET_CONTENT); activity.startActivityForResult(intent, resultCode); }
From source file:Main.java
public static void sendText(Context context, String text) { String mimeType = getMimeTypeForExtension("txt"); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType(mimeType);//from w ww . j a v a 2 s . c om intent.putExtra(Intent.EXTRA_TEXT, text); context.startActivity(intent); }