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

}

From source file:Main.java

public static void shareOnTwitter(Context pContext, String urlToShare) {

    Intent tweetIntent = new Intent(Intent.ACTION_SEND);
    tweetIntent.putExtra(Intent.EXTRA_TEXT, urlToShare);
    tweetIntent.setType("text/plain");

    PackageManager packManager = pContext.getPackageManager();
    List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,
            PackageManager.MATCH_DEFAULT_ONLY);

    boolean resolved = false;
    for (ResolveInfo resolveInfo : resolvedInfoList) {
        if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
            tweetIntent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
            resolved = true;// w  w w  . j  av a  2s  .com
            break;
        }
    }
    if (resolved) {
        pContext.startActivity(tweetIntent);
    } else {
        Intent i = new Intent();
        i.putExtra(Intent.EXTRA_TEXT, urlToShare);
        i.setAction(Intent.ACTION_VIEW);
        i.setData(Uri.parse("https://twitter.com/intent/tweet?text=message&via=profileName"));
        pContext.startActivity(i);
    }
}

From source file:Main.java

public static void sendMail(Context context, String dstAddr, String subject, String text) {
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

    String[] address = { dstAddr };
    emailIntent.putExtra(Intent.EXTRA_EMAIL, address);
    emailIntent.setType("message/rfc822");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

From source file:Main.java

public static void sendEmail(String email, Context context) {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { email };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    emailIntent.setType(PLAIN_TEXT);
    context.startActivity(emailIntent);/*w  ww.  ja v a2 s .c  om*/
}

From source file:Main.java

@NonNull
public static Intent openContent(@NonNull Uri uri) {
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final String mime = URLConnection.guessContentTypeFromName(uri.toString());
    if (!TextUtils.isEmpty(mime)) {
        intent.setType(mime);
    }//from   ww  w .  ja va  2 s  .c  o m
    return intent;
}

From source file:Main.java

public static void jumpToSystemShareImages(Context context, ArrayList<Uri> imageUris) {
    Intent shareIntent = new Intent();
    shareIntent.setAction("android.intent.action.SEND_MULTIPLE");
    shareIntent.putParcelableArrayListExtra("android.intent.extra.STREAM", imageUris);
    shareIntent.setType("image/*");
    context.startActivity(shareIntent);//  www  .  j av a2s  .com
}

From source file:Main.java

public static void sendSms(Context context, String phoneNum, String content) {
    Intent mIntent = new Intent(Intent.ACTION_VIEW);
    mIntent.putExtra("address", phoneNum);
    mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mIntent.putExtra("sms_body", content);
    mIntent.setType("vnd.android-dir/mms-sms");
    context.startActivity(mIntent);//  w w w  . j a  v  a 2  s  .  c om
}

From source file:Main.java

public static void sendMail(Context context, String email) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    sendIntent.putExtra(Intent.EXTRA_TEXT, "");
    sendIntent.setType("text/plain");
    context.startActivity(sendIntent);//from   w ww.  j  ava  2 s  . c om
}

From source file:Main.java

public static Intent getShareHtmlIntent(String htmlText) {
    Intent textIntent = new Intent();
    textIntent.setAction(Intent.ACTION_SEND);
    textIntent.putExtra(Intent.EXTRA_TEXT, "This is html");
    textIntent.putExtra(Intent.EXTRA_HTML_TEXT, htmlText);
    textIntent.setType("text/plain");
    return textIntent;
}

From source file:Main.java

public static void share(Context pContext, String urlToShare, String titleChosser, String subject) {

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
    intent.setType("text/plain");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    pContext.startActivity(Intent.createChooser(intent, titleChosser));
}