List of usage examples for android.content Intent setType
public @NonNull Intent setType(@Nullable String type)
From source file:im.delight.android.baselib.Social.java
/** * Constructs an SMS Intent for the given message details and opens the application chooser for this Intent * * @param recipient the recipient's phone number or `null` * @param body the body of the message/* www. j a v a 2 s . c om*/ * @param captionRes the string resource ID for the application chooser's window title * @param context the Context instance to start the Intent from * @throws Exception if there was an error trying to launch the SMS Intent */ public static void sendSMS(final String recipient, final String body, final int captionRes, final Context context) throws Exception { final Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType(HTTP.PLAIN_TEXT_TYPE); if (recipient != null && recipient.length() > 0) { intent.setData(Uri.parse("smsto:" + recipient)); } else { intent.setData(Uri.parse("sms:")); } intent.putExtra("sms_body", body); intent.putExtra(Intent.EXTRA_TEXT, body); if (context != null) { // offer a selection of all applications that can handle the SMS Intent context.startActivity(Intent.createChooser(intent, context.getString(captionRes))); } }
From source file:Main.java
public static void openMailChooser(Context context, String text, String[] mails, String subject) { Intent mailIntent = new Intent(); mailIntent.setAction(Intent.ACTION_SEND); mailIntent.putExtra(Intent.EXTRA_TEXT, text); mailIntent.putExtra(Intent.EXTRA_EMAIL, mails); mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); mailIntent.setType(INTENT_TYPE_MSG); PackageManager pm = context.getPackageManager(); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType(INTENT_TYPE_TEXT); Intent openInChooser = Intent.createChooser(mailIntent, ""); List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0); List<LabeledIntent> intentList = new ArrayList<LabeledIntent>(); for (ResolveInfo ri : resInfo) { String packageName = ri.activityInfo.packageName; if (packageName.contains(PACKAGE_EMAIL)) { mailIntent.setPackage(packageName); } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) { Intent intent = new Intent(); intent.setComponent(new ComponentName(packageName, ri.activityInfo.name)); intent.setAction(Intent.ACTION_SEND); intent.setType(INTENT_TYPE_TEXT); if (packageName.contains(PACKAGE_MMS)) { intent.putExtra("subject", subject); intent.putExtra("sms_body", text); intent.putExtra("address", mails[0]); intent.setType(INTENT_TYPE_MSG); } else if (packageName.contains(PACKAGE_GMAIL)) { intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_EMAIL, mails); intent.setType(INTENT_TYPE_MSG); }/*from w w w . j a v a 2 s . co m*/ intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon)); } } LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]); openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents); context.startActivity(openInChooser); }
From source file:at.wada811.utils.IntentUtils.java
/** * Intent??/*w ww . j a va 2 s .c o m*/ * * @param intent * @param uri * @param mimeType * @return */ public static Intent addFile(Intent intent, Uri uri, String mimeType) { intent.setType(mimeType); intent.putExtra(Intent.EXTRA_STREAM, uri); return intent; }
From source file:at.wada811.utils.IntentUtils.java
/** * ??Intent??/* w w w .j a v a 2s.c om*/ * * @param mailto * @param cc * @param bcc * @param subject * @param body */ public static Intent createSendMailIntent(String[] mailto, String[] cc, String[] bcc, String subject, String body) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(HTTP.PLAIN_TEXT_TYPE); intent.putExtra(Intent.EXTRA_EMAIL, mailto); intent.putExtra(Intent.EXTRA_CC, cc); intent.putExtra(Intent.EXTRA_BCC, bcc); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, body); return intent; }
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and shares the specified plain text and subject line using the selected application * * @param context a context reference/*from ww w. ja va2s . co m*/ * @param windowTitle the title for the application chooser's window * @param bodyTextToShare the body text to be shared * @param subjectTextToShare the title or subject for the message to be shared, if supported by the target application */ public static void shareText(final Context context, final String windowTitle, final String bodyTextToShare, final String subjectTextToShare) { final Intent intentInvite = new Intent(Intent.ACTION_SEND); intentInvite.setType(HTTP.PLAIN_TEXT_TYPE); intentInvite.putExtra(Intent.EXTRA_SUBJECT, subjectTextToShare); intentInvite.putExtra(Intent.EXTRA_TEXT, bodyTextToShare); context.startActivity(Intent.createChooser(intentInvite, windowTitle)); }
From source file:at.wada811.utils.IntentUtils.java
/** * ?Intent??/*from w w w . j av a 2 s . co m*/ */ public static Intent createSendTextIntent(String text) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, text); return intent; }
From source file:at.wada811.utils.IntentUtils.java
/** * ??Intent??/*from www.j a v a 2 s .c om*/ */ public static Intent createSendImageIntent(String filePath) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType(MediaUtils.getMimeType(filePath)); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath)); return intent; }
From source file:im.delight.android.commons.Social.java
/** * Displays an application chooser and composes the described text message (SMS) using the selected application * * @param recipientPhone the recipient's phone number or `null` * @param bodyText the body text of the message * @param captionRes a string resource ID for the title of the application chooser's window * @param context a context reference//w w w .ja v a 2s . com * @throws Exception if there was an error trying to launch the SMS application */ public static void sendSms(final String recipientPhone, final String bodyText, final int captionRes, final Context context) throws Exception { final Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType(HTTP.PLAIN_TEXT_TYPE); if (recipientPhone != null && recipientPhone.length() > 0) { intent.setData(Uri.parse("smsto:" + recipientPhone)); } else { intent.setData(Uri.parse("sms:")); } intent.putExtra("sms_body", bodyText); intent.putExtra(Intent.EXTRA_TEXT, bodyText); if (context != null) { // offer a selection of all applications that can handle the SMS Intent context.startActivity(Intent.createChooser(intent, context.getString(captionRes))); } }
From source file:im.delight.android.baselib.Social.java
/** * Constructs an Intent for sharing/sending a file 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 file the File instance to be shared * @param mimeType the MIME type for the file to be shared (e.g. image/jpeg) * @param messageTitle the message title/subject that may be provided in addition to the file, if supported by the target app *///from www . j a v a 2 s. c om public static void shareFile(Context context, String windowTitle, File file, final String mimeType, String messageTitle) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType(mimeType); intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); context.startActivity(Intent.createChooser(intent, windowTitle)); }
From source file:com.eyekabob.util.EyekabobHelper.java
public static void launchEmail(Activity activity) { Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setType("plain/text"); String to[] = { "philj21@yahoo.com", "adam.sill01@gmail.com", "coffbr01@gmail.com" }; emailIntent.putExtra(Intent.EXTRA_EMAIL, to); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Eyekabob Advertising"); String label = activity.getResources().getString(R.string.write_email); activity.startActivity(Intent.createChooser(emailIntent, label)); }