List of usage examples for android.content Intent ACTION_SEND
String ACTION_SEND
To view the source code for android.content Intent ACTION_SEND.
Click Source Link
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 ww w .j a v a 2s. c o m }
From source file:Main.java
public static void showEmailDialog(final Context context, final String subject) { new AlertDialog.Builder(context).setTitle("Email Us").setMessage( "Please send email with As many details as possible. We will look into it as soon as possible. \n\nPlease DO NOT change subject and email address. Continue to Email?") .setPositiveButton(android.R.string.ok, new OnClickListener() { @Override//from www . ja va 2s . co m public void onClick(DialogInterface dialogInterface, int i) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/html"); // intent.putExtra(Intent.EXTRA_EMAIL, R.string.app_email); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, ""); context.startActivity(Intent.createChooser(intent, "Send Email")); } }).setIcon(android.R.drawable.ic_dialog_info).show(); }
From source file:Main.java
public static void shareFile(Context context, String title, String filePath) { Intent intent = new Intent(Intent.ACTION_SEND); Uri uri = Uri.parse("file://" + filePath); intent.setType("*/*"); intent.putExtra(Intent.EXTRA_STREAM, uri); context.startActivity(Intent.createChooser(intent, title)); }
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 av a 2 s . c o 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:Main.java
public static List<ResolveInfo> getShareTargets(Context ctx) { Intent intent = new Intent(Intent.ACTION_SEND, null); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("text/plain"); PackageManager pm = ctx.getPackageManager(); return pm.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); }
From source file:Main.java
public static boolean sendMail(Context context, String destination, String subject, String body) { Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); String aEmailList[] = { destination }; emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList); if (subject != null) { emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); }/*from ww w . j a v a2 s . c om*/ if (body != null) { emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body); } emailIntent.setType("plain/text"); boolean ret = true; try { context.startActivity(emailIntent); } catch (Exception e) { ret = false; } return ret; }
From source file:Main.java
public static void shareOnFacebook(Context pContext, String urlToShare) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); // intent.putExtra(Intent.EXTRA_SUBJECT, "Foo bar"); // NB: has no effect! intent.putExtra(Intent.EXTRA_TEXT, urlToShare); // See if official Facebook app is found boolean facebookAppFound = false; List<ResolveInfo> matches = pContext.getPackageManager().queryIntentActivities(intent, 0); for (ResolveInfo info : matches) { if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) { intent.setPackage(info.activityInfo.packageName); facebookAppFound = true;/*from w w w.j a va 2s . c o m*/ break; } } // As fallback, launch sharer.php in a browser if (!facebookAppFound) { String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare; intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl)); } pContext.startActivity(intent); }
From source file:Main.java
public static void callSysShare(Context context, String chooserTitle, String shareTitle, String shareText, String mime, Uri uri) {//from w ww . ja v a 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 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;/* ww w .j a v a2 s . c om*/ 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 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 ww w . j a 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; }