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 send(Context context, String path) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    PackageManager pm = context.getPackageManager();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    boolean flag = false;
    for (ResolveInfo info : list) {
        if (info.activityInfo.packageName.toLowerCase().contains("bluetooth")
                || info.activityInfo.name.toLowerCase().contains("bluetooth")) {
            ApplicationInfo appInfo = null;
            try {
                appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {

            }/*w  w w .  j  a v  a  2  s . c  om*/
            if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0
                    && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                flag = true;
                break;
            }
        }
    }
    if (!flag) {
        return;
    }
    context.startActivity(intent);
}

From source file:Main.java

public static Intent startGetPicPhotoAlbum() {
    Intent intent = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    } else {/* w w  w .j  a v a  2s  . com*/
        intent = new Intent(Intent.ACTION_GET_CONTENT);
    }
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    return intent;
}

From source file:Main.java

public static void shareToGMail(Context context, String[] email, String subject, String content) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content);
    final PackageManager pm = context.getPackageManager();
    final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
    ResolveInfo best = null;/*from  w  w w .  j  a  va  2s  .  c o  m*/
    for (final ResolveInfo info : matches)
        if (info.activityInfo.packageName.endsWith(".gm")
                || info.activityInfo.name.toLowerCase().contains("gmail"))
            best = info;
    if (best != null)
        emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
    context.startActivity(emailIntent);
}

From source file:Main.java

public static void callSysShare(Context context, String chooserTitle, String shareTitle, String shareText,
        String mime, Uri uri) {/*from   ww  w .jav  a 2  s.com*/
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_TEXT, shareText);
    intent.putExtra(Intent.EXTRA_SUBJECT, shareTitle);
    intent.setType(mime);
    if (uri != null) {
        intent.putExtra(Intent.EXTRA_STREAM, uri);
    }
    context.startActivity(Intent.createChooser(intent, chooserTitle));
}

From source file:Main.java

public static Intent newEmailIntent(Context context, String address, String subject, String body, String cc) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address });
    intent.putExtra(Intent.EXTRA_TEXT, body);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_CC, cc);
    intent.setType("message/rfc822");
    return intent;
}

From source file:Main.java

public static Intent newEmailIntent(String toAddress, String subject, String body, String cc) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { toAddress });
    intent.putExtra(Intent.EXTRA_TEXT, body);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_CC, cc);
    intent.setType("message/rfc822");
    return intent;
}

From source file:edu.mit.mobile.android.livingpostcards.data.Card.java

/**
 * Creates an {@link Intent#ACTION_SEND} intent to share the given card.
 *
 * @param context//from   www  . j  ava2s.c  o m
 * @param webUrl
 *            the content of the card's {@link Card#COL_WEB_URL} field. Can be a relative URL.
 * @param title
 *            the title of the card
 * @return an intent, within a chooser, that can be used with
 *         {@link Context#startActivity(Intent)}
 */
public static Intent createShareIntent(Context context, String webUrl, CharSequence title) {
    final NetworkClient nc = LocastApplication.getNetworkClient(context,
            Authenticator.getFirstAccount(context));
    final Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");
    sendIntent.putExtra(Intent.EXTRA_TEXT,
            context.getString(R.string.send_intent_message, nc.getFullUrlAsString(webUrl)));
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.send_intent_subject, title));
    return Intent.createChooser(sendIntent, context.getString(R.string.send_intent_chooser_title));

}

From source file:Main.java

public static void feedback(Context context, String feedBackEmailId, String emailSubject, String msg) {

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { feedBackEmailId });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, msg);
    emailIntent.setType("message/rfc822");
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(context, emailIntent)) {
        context.startActivity(emailIntent);
    } else {//from  w  w w  . j a  va2s .co  m
        Toast.makeText(context, "No Email Application Found", Toast.LENGTH_LONG).show();
    }
}

From source file:com.github.longkai.zhihu.util.Utils.java

/**
 * ??/*from   www  . j a  v a  2  s.  co m*/
 * @param context
 * @param subject 
 * @param content 
 * @return intent
 */
public static Intent share(Context context, String subject, String content) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("text/plain");
    share.putExtra(Intent.EXTRA_SUBJECT, subject);
    share.putExtra(Intent.EXTRA_TEXT, content + context.getString(R.string.share_from));
    return share;
}

From source file:im.delight.android.baselib.Social.java

/**
 * Constructs an Intent for sharing/sending plain text and starts Activity chooser for that Intent
 *
 * @param context Context reference to start the Activity chooser from
 * @param windowTitle the string to be used as the window title for the Activity chooser
 * @param messageText the body text for the message to be shared
 * @param messageTitle the title/subject for the message to be shared, if supported by the target app
 *//*from   w  w w .j  a v  a  2s  . c  o  m*/
public static void shareText(Context context, String windowTitle, String messageText, String messageTitle) {
    Intent intentInvite = new Intent(Intent.ACTION_SEND);
    intentInvite.setType(HTTP.PLAIN_TEXT_TYPE);
    intentInvite.putExtra(Intent.EXTRA_SUBJECT, messageTitle);
    intentInvite.putExtra(Intent.EXTRA_TEXT, messageText);
    context.startActivity(Intent.createChooser(intentInvite, windowTitle));
}