Example usage for android.content Intent setType

List of usage examples for android.content Intent setType

Introduction

In this page you can find the example usage for android.content Intent setType.

Prototype

public @NonNull Intent setType(@Nullable String type) 

Source Link

Document

Set an explicit MIME data type.

Usage

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.setData(Uri.fromFile(file));/*ww w.  j a v a2s  .  c o m*/
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

}

From source file:Main.java

public static void jumpToSystemShareText(Context context, String content) {
    Intent sendIntent = new Intent();
    sendIntent.setAction("android.intent.action.SEND");
    sendIntent.putExtra("android.intent.extra.TEXT", content);
    sendIntent.setType("text/plain");
    context.startActivity(sendIntent);// w  ww. jav a2  s.  c om
}

From source file:com.app.common.util.IntentUtils.java

public static void startEmailActivity(Context context, String to, String subject, String body) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");

    if (!TextUtils.isEmpty(to)) {
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    }//from w ww.  jav a2s  .  c o m
    if (!TextUtils.isEmpty(subject)) {
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    }
    if (!TextUtils.isEmpty(body)) {
        intent.putExtra(Intent.EXTRA_TEXT, body);
    }

    final PackageManager pm = (PackageManager) context.getPackageManager();
    try {
        if (pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) {
            intent.setType("text/plain");
        }
    } catch (Exception e) {
        Log.w("Exception encountered while looking for email intent receiver.", e);
    }

    context.startActivity(intent);
}

From source file:Main.java

/**
 * Returns an intent calling the android chooser. The chooser will provide apps, which listen to one of the following actions
 * {@link Intent#ACTION_GET_CONTENT} , {@link MediaStore#ACTION_IMAGE_CAPTURE}, {@link MediaStore#ACTION_VIDEO_CAPTURE},
 * {@link MediaStore.Audio.Media#RECORD_SOUND_ACTION}
 * //from   w  w w. ja  v  a2 s  . co  m
 * @return Intent that opens the app chooser.
 */
public static Intent getChooserIntent() {
    // GET_CONTENT Apps
    Intent getContentIntent = new Intent();
    getContentIntent.setAction(Intent.ACTION_GET_CONTENT);
    getContentIntent.setType("*/*");
    getContentIntent.addCategory(Intent.CATEGORY_OPENABLE);
    // ACTION_IMAGE_CAPTURE Apps
    Intent captureImageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // ACTION_VIDEO_CAPTURE Apps
    Intent captureVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    // RECORD_SOUND_ACTION Apps
    Intent recordSoungIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    Intent finalIntent = Intent.createChooser(getContentIntent, "test");
    finalIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            new Intent[] { captureImageIntent, captureVideoIntent, recordSoungIntent });
    return finalIntent;
}

From source file:Main.java

public static void setClickable(final TextView textView) {
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    Spannable sp = (Spannable) textView.getText();
    ImageSpan[] images = sp.getSpans(0, textView.getText().length(), ImageSpan.class);

    for (ImageSpan span : images) {
        final String image_src = span.getSource();
        final int start = sp.getSpanStart(span);
        final int end = sp.getSpanEnd(span);

        ClickableSpan click_span = new ClickableSpan() {
            @Override//from  w  ww.j  a va  2 s.  c  o  m
            public void onClick(View widget) {
                String[] strs = image_src.split("/");
                String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/LilyClient/"
                        + strs[strs.length - 2] + "-" + strs[strs.length - 1];

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setType("image/*");
                intent.setDataAndType(Uri.fromFile(new File(filePath)), "image/*");
                textView.getContext().startActivity(intent);

            }
        };
        ClickableSpan[] click_spans = sp.getSpans(start, end, ClickableSpan.class);
        if (click_spans.length != 0) {
            for (ClickableSpan c_span : click_spans) {
                sp.removeSpan(c_span);
            }
        }
        sp.setSpan(click_span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}

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 jumpToSystemShareImage(Context context, String imageUri) {
    Intent shareIntent = new Intent();
    shareIntent.setAction("android.intent.action.SEND");
    shareIntent.putExtra("android.intent.extra.STREAM", imageUri);
    shareIntent.setType("image/*");
    context.startActivity(shareIntent);/*from   w  ww  .  j a  v a  2  s .com*/
}

From source file:Main.java

/** Launch an email intent if the device is capable.
 *
 * @param activity The parent activity (for context)
 * @param addr The address to email (not the full URI)
 * @param text The email body// ww  w  .  ja v a2s.co  m
 */
public static void launchEmailIntent(final Activity activity, String addr, String text) {
    Log.i(LOG_TAG, "Launch email intent from " + activity.getLocalClassName());
    // create email intent
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { addr });
    emailIntent.setType("text/plain");
    // make sure there is an activity which can handle the intent.
    PackageManager emailpackageManager = activity.getPackageManager();
    List<ResolveInfo> emailresolveInfos = emailpackageManager.queryIntentActivities(emailIntent, 0);
    if (emailresolveInfos.size() > 0) {
        activity.startActivity(emailIntent);
    }
}

From source file:Main.java

public static Intent pickContact(String with) {
    final Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://com.android.contacts/contacts"));
    if (!TextUtils.isEmpty(with)) {
        intent.setType(with);
    }/*from   ww w. jav a 2 s.  co  m*/
    return intent;
}

From source file:Main.java

public static void installApk(Context context, File apkfile) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("application/vnd.android.package-archive");
    intent.setData(Uri.fromFile(apkfile));
    intent.setDataAndType(Uri.fromFile(apkfile), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);//  w  ww.  j a  v a  2 s  . c o  m
}