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 boolean pickFile(Activity activity, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*");
    activity.startActivityForResult(intent, requestCode);
    return true;/*from   www . jav a 2 s .  c  o  m*/
}

From source file:Main.java

public static Intent getAndroidShareIntent(CharSequence chooseTitle, CharSequence subject,
        CharSequence content) {//from ww  w . j av a 2s.c om
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    shareIntent.putExtra(Intent.EXTRA_TEXT, content);
    return Intent.createChooser(shareIntent, chooseTitle);
}

From source file:Main.java

/**
 * Creates a intent with an image//from  w w  w.j a  va  2s. co m
 *
 * @param image
 * @return
 */
public static Intent createIntentFromImage(File image) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/*");
    return share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
}

From source file:Main.java

public static void selectImage(Activity activity, int i) {
    Intent intent = new Intent("android.intent.action.GET_CONTENT");
    intent.setType("image/*");
    activity.startActivityForResult(Intent.createChooser(intent, activity.getString(0x7f080083)), i);
}

From source file:Main.java

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

From source file:Main.java

public static Intent getAndroidShareIntent(CharSequence chooseTitle, CharSequence subject,
        CharSequence content) {//from  w  w w .  j a va  2s. c o m
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, content);
    return Intent.createChooser(shareIntent, chooseTitle);
}

From source file:Main.java

public static Intent pickFile(String mimeType) {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(mimeType);
    return intent;
}

From source file:Main.java

public static void shareText(Context ctx, String title, String text) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    //intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    ctx.startActivity(Intent.createChooser(intent, title));
    /* List<ResolveInfo> ris = getShareTargets(ctx);
     if (ris != null && ris.size() > 0) {
     ctx.startActivity(Intent.createChooser(intent, title));
     }*///from   www .  j  a  v  a 2s. c om
}

From source file:Main.java

/**
 * Drafts an email to the given email address, with the given subject line and message
 * @param context//  w  w  w  .j  av a 2s.c  om
 * @param emailAddress
 * @param subject
 * @param message
 */
public static void emailDeveloper(Context context, String emailAddress, String subject, String message) {

    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { emailAddress });
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, message);

    context.startActivity(i);
}

From source file:Main.java

public static void openFileBrowser(Activity a, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    a.startActivityForResult(intent, requestCode);
}