List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
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 callSysShare(Context context, String chooserTitle, String shareTitle, String shareText, String mime, Uri uri) {/*ww w .j a va 2s .c om*/ 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 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 ww .j a v a2 s . c om 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:Main.java
public static void sendFeedback2(Context context) { String versionName = ""; try {/*from w ww . j av a 2 s . c o m*/ versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } StringBuffer sb = new StringBuffer(); sb.append("We would like to hear your feedback and improvement ideas. Please feel free to share below :") .append("\r\n").append("\r\n").append("\r\n").append("Attach Screenshots (if any) : ") .append("\r\n").append("\r\n").append("\r\n").append("Running on ").append(android.os.Build.MODEL) .append("\r\n").append("OS Version : ").append(android.os.Build.VERSION.RELEASE).append("\r\n") .append("Client Version : ").append(versionName); Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "messageplus_feedback@starhub.com", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Message+ - Feedback"); emailIntent.putExtra(Intent.EXTRA_TEXT, sb.toString()); context.startActivity(Intent.createChooser(emailIntent, "Choose email client")); }
From source file:com.duy.ascii.sharedcode.ShareUtil.java
public static void shareImage(Context context, File file) { Uri uri;/*from ww w. j a va2 s. c o m*/ if (Build.VERSION.SDK_INT >= 24) { uri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", file); } else { uri = Uri.fromFile(file); } Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/*"); context.startActivity(Intent.createChooser(intent, "Share image via")); }
From source file:Main.java
public static void ShareApplication(Context mContext) { Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_SUBJECT, "Search Sri Lanka Railway Time Table"); intent.putExtra(Intent.EXTRA_TITLE, "Search Sri Lanka Railway Time Table"); intent.putExtra(Intent.EXTRA_TEXT,//from w ww . ja v a2 s .c o m "Search \"Sri Lanka Railway Time Table\" on your Android. http://market.android.com/details?id=com.aselalee.trainschedule"); mContext.startActivity(Intent.createChooser(intent, "Spread the word")); return; }
From source file:Main.java
public static void sendEmail(Context ctx, String[] emailAddresses, String[] CCAddresses, String subject, String message) {//from w ww . j av a 2 s . c o m Intent emailIntent = new Intent(Intent.ACTION_SEND); // emailIntent.setType("text/plain"); emailIntent.setData(Uri.parse("mailto:")); String[] to = emailAddresses; String[] cc = CCAddresses; emailIntent.putExtra(Intent.EXTRA_EMAIL, to); if (CCAddresses != null) { emailIntent.putExtra(Intent.EXTRA_CC, cc); } emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, message); emailIntent.setType("message/rfc822"); ctx.startActivity(Intent.createChooser(emailIntent, "Email")); }
From source file:Main.java
public static void sendEmail(Context context, String chooserTitle, String mailAddress, String subject, String preContent) {/*ww w. j a v a 2 s . c o m*/ final Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { mailAddress }); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); String content = "\n\n=====================\n"; content += "Device Environment: \n----\n" + preContent; emailIntent.putExtra(Intent.EXTRA_TEXT, content); context.startActivity(Intent.createChooser(emailIntent, chooserTitle)); }
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)); }
From source file:Main.java
@SuppressLint("InlinedApi") public static void launchPlainText(Context context, String text, CharSequence chooserTitle) { // See http://android-developers.blogspot.com/2012/02/share-with-intents.html Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); intent.putExtra(Intent.EXTRA_TEXT, text); // intent.putExtra( Intent.EXTRA_SUBJECT, subject ); // intent.putExtra( Intent.EXTRA_EMAIL, new String[] { emailTo } ); context.startActivity(Intent.createChooser(intent, chooserTitle)); }