Android Customize Intent Share
This post about how to share the data from particular application like : whatsapp m facebook , twitter , gmail etc..
Share Intent via GMAIL
This post about how to share the data from particular application like : whatsapp m facebook , twitter , gmail etc..
Share Intent via GMAIL
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, Html.fromHtml(shareTitle)
.toString());
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(shareContent)
.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).contains("android.gm"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
mContext.startActivity(shareIntent);
break;
}
}
Share Intent Via TWITTER
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, Html.fromHtml(shareTitle)
.toString());
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(shareContent)
.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ("com.twitter.android.PostActivity".equals(app.activityInfo.name))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
mContext.startActivity(shareIntent);
break;
}
}
Share Intent Via Facebook
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, Html.fromHtml(shareTitle)
.toString());
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(shareContent)
.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).contains("facebook"))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
mContext.startActivity(shareIntent);
break;
}
}
Share Intent Via WhatsApp
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/html");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, Html.fromHtml(shareTitle)
.toString());
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(shareContent)
.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("com.whatsapp")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
mContext.startActivity(shareIntent);
break;
}
}