IntentChooser - different intents for different apps - android

I've found this answer, which explains how to create a different intent for each app, but some why it does not work:
here is the code that reproduces the issue, you can even comment the if and you will stick get the text and not the twitter
public Intent getShareChooserIntent(Context context) {
Intent basicIntent = new Intent();
basicIntent.setAction(Intent.ACTION_SEND);
basicIntent.setType("text/plain");
basicIntent.putExtra(Intent.EXTRA_TEXT, "text");
basicIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
PackageManager pm = context.getPackageManager();
Intent openInChooser = Intent.createChooser(basicIntent, "share");
List<ResolveInfo> resInfo = pm.queryIntentActivities(basicIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
Intent realIntent = new Intent();
realIntent.setAction(Intent.ACTION_SEND);
realIntent.setType("text/plain");
realIntent.putExtra(Intent.EXTRA_TEXT, "text");
realIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
if (packageName.contains("twitter")) // !!!!THIS LINE!!!!
realIntent.putExtra(Intent.EXTRA_TEXT, "twitter");
intentList.add(new LabeledIntent(realIntent, packageName, ri.loadLabel(pm), ri.icon));
}
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray( new LabeledIntent[ intentList.size()]));
return openInChooser;
}
what am I doing wrong?

Not sure what getShareBasicIntent do, but this code works fine for me (checked it with and without twitter)
static public Intent getShareChooserIntent(Context context) {
PackageManager pm = context.getPackageManager();
// Note that this intent should only be for email
// to avoid duplicates in the list
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_TEXT, "not twitter");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.setType("message/rfc822");
Intent openInChooser = Intent.createChooser(emailIntent, "share");
// the basic intent used to query all the activities that can support
// text sharing
Intent basicIntent = new Intent();
basicIntent.setAction(Intent.ACTION_SEND);
basicIntent.setType("text/plain");
List<ResolveInfo> resInfo = pm.queryIntentActivities(basicIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
Intent intent=new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "not twitter");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.setPackage(packageName);
if (packageName.contains("twitter")) {
intent.putExtra(Intent.EXTRA_TEXT, "twitter");
}
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray( new LabeledIntent[ intentList.size()]));
return openInChooser;
}

Related

Android share intent of copy to clipboard

I want to detect which share action is selected in my app
my share method:
public void share(String subject, String message) {
List<Intent> shareIntentsLists = new ArrayList<Intent>();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
List<ResolveInfo> resInfos = getCurrentActivity().getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfos.isEmpty()) {
for (ResolveInfo resInfo : resInfos) {
String packageName = resInfo.activityInfo.packageName;
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.setPackage(packageName);
shareIntentsLists.add(intent);
}
if (!shareIntentsLists.isEmpty()) {
Intent chooserIntent = Intent.createChooser(shareIntentsLists.remove(0), "");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, shareIntentsLists.toArray(new Parcelable[]{}));
getCurrentActivity().startActivity(chooserIntent);
}
}
}
if put url link to message parameter and would show copy button to copy url to clipboard
like this
How do I detect this copy button is pressed?
Because this button is not created in shareIntentsLists

Default Messaging App version 4.2.1 is not able show in intent chooser dialog with other apps like whatsapp, etc

I want to show only Messaging app and Whatsapp application in Intentchooser. The following code is working fine with some other devices like moto e, g, etc.. But in some other devices its now showing the default messaging application. This is my code. Please help me.
private void shareTheApp() {
Resources resources = getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
emailIntent.setAction(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
if (packageName.contains("com.whatsapp")) {
emailIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
emailIntent.setType("text/plain");
emailIntent.setPackage(packageName);
}
if (packageName.contains("mms")) {
isMmsAvailable = true;
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if (packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
}
intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
}
}
if(!isMmsAvailable) {
isMmsAvailable = false;
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("sms:"));
smsIntent.putExtra("sms_body", resources.getString(R.string.share_text));
intentList.add(new LabeledIntent(smsIntent, "", "Messaging", R.drawable.ic_launcher));
}
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
Intent openInChooser = Intent.createChooser(emailIntent, getResources().getString(R.string.openchooser_tittle));
openInChooser.addCategory(Intent.CATEGORY_DEFAULT);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
startActivity(openInChooser);
}
Yes, I solved this problem :) below the code.
Resources resources = getResources();
List<Intent> selectedIntents = new ArrayList<Intent>();
Intent shareIntent=new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfos=getPackageManager().queryIntentActivities(shareIntent, 0);
if(!resInfos.isEmpty()){
for(ResolveInfo resInfo : resInfos) {
String packageName=resInfo.activityInfo.packageName;
if(packageName.contains("com.whatsapp")){
Intent intent=new Intent();
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
intent.setPackage(packageName);
selectedIntents.add(intent);
}
}
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(sendIntent, 0);
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if (packageName.contains("mms")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if (packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_text));
selectedIntents.add(intent);
}
}
}
if(!selectedIntents.isEmpty()){
Intent chooserIntent = null;
chooserIntent = Intent.createChooser(selectedIntents.get(0), resources.getString(R.string.openchooser_tittle));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, selectedIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
}
we need to call both action ACTION_SEND and ACTION_VIEW. Now it will show in intent chooser for both type of messaging app. Hope it might be usefull for some else.

android filter app returns two twitter

I am trying to filter the app i have in the phone, facebook and twitter are what I want to find. Below is the code i use, and it works fine before, it filter twitter and facebook for me to post something. Then later it become i filter two twitter apps. Anyone know why?
I use debug more and found these, how come i get two twitter package. I have tried delete and reinstall my twitter app, it won't work.
ResolveInfo{445f8600 com.twitter.android/.composer.ComposerActivity m=0x608000}
ResolveInfo{445f14d0 com.twitter.android/.DMActivity m=0x608000}
private void shareContent() {
UtuBaseActivity activity = (UtuBaseActivity) getActivity();
if (activity == null || activity.isFinishing())
return;
if (promotionDetail == null)
return;
String title = getResources().getString(R.string.share_chooser_title);
String app_name = getResources().getString(R.string.app_name);
List<Intent> targetShareIntents = new ArrayList<>();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfos = activity.getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfos.isEmpty()) {
for (ResolveInfo resInfo : resInfos) {
String packageName = resInfo.activityInfo.packageName;
if (packageName.contains("com.twitter.android") || packageName.contains("com.facebook.katana")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, app_name);
intent.putExtra(Intent.EXTRA_TEXT, promotionDetail.getCoverpicture());
intent.setPackage(packageName);
targetShareIntents.add(intent);
}
}
if (!targetShareIntents.isEmpty()) {
Intent chooserIntent = Intent.createChooser(targetShareIntents.remove(0), title);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
} else {
// As fallback, launch sharer.php in a browser
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + promotionDetail.getCoverpicture();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(i);
}
}
}
add this, it works tested.
check parent name equals to com.twitter.android.MainActivity
private void shareContent() {
UtuBaseActivity activity = (UtuBaseActivity) getActivity();
if (activity == null || activity.isFinishing())
return;
if (promotionDetail == null)
return;
String title = getResources().getString(R.string.share_chooser_title);
String app_name = getResources().getString(R.string.app_name);
List<Intent> targetShareIntents = new ArrayList<>();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
List<ResolveInfo> resInfos = activity.getPackageManager().queryIntentActivities(shareIntent, 0);
if (!resInfos.isEmpty()) {
for (ResolveInfo resInfo : resInfos) {
String packageName = resInfo.activityInfo.packageName;
String parentName = resInfo.activityInfo.parentActivityName;
if (packageName.contains("com.twitter.android") || packageName.contains("com.facebook.katana")) {
if (packageName.contains("com.twitter.android"))
if (!parentName.equals("com.twitter.android.MainActivity"))
continue;
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, resInfo.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, app_name);
intent.putExtra(Intent.EXTRA_TEXT, promotionDetail.getCoverpicture());
intent.setPackage(packageName);
targetShareIntents.add(intent);
}
}
if (!targetShareIntents.isEmpty()) {
Intent chooserIntent = Intent.createChooser(targetShareIntents.remove(0), title);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
} else {
// As fallback, launch sharer.php in a browser
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + promotionDetail.getCoverpicture();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(i);
}
}
}

ShareActionProvider Android system menu

I have a little problem in my menu. I click in my MenuItem, then Share and I would like open my Intent (Chooser). But I've android system item between.
My code :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem item = menu.findItem(R.id.file);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
setShareIntent();
return true;
}
private void setShareIntent() {
Resources resources = getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));
emailIntent.setType("message/rfc822");
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if(packageName.contains("android.email")) {
emailIntent.setPackage(packageName);
} else if(packageName.contains("twitter") || packageName.contains("facebook") || packageName.contains("mms") || packageName.contains("android.gm")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if(packageName.contains("twitter")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_twitter));
} else if(packageName.contains("facebook")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_facebook));
} else if(packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_sms));
} else if(packageName.contains("android.gm")) {
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
intent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));
intent.setType("message/rfc822");
}
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);
mShareActionProvider.setShareIntent(openInChooser);
//startActivity(openInChooser);
}
Is this line ? :
mShareActionProvider.setShareIntent(openInChooser);
I don't see.
My menu :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.FragmentsSliderNews" >
<item android:id="#+id/file"
android:title="Share"
android:icon="#drawable/ic_action_share"
app:actionProviderClass=
"android.support.v7.widget.ShareActionProvider">
</item>
</menu>
Thank you all for yours answers.
Get rid of createChooser(). You only use that with startActivity(), not for things like ShareActionProvider.
share via option in android
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "News for you!");
intent.putExtra(android.content.Intent.EXTRA_TEXT,"Additional text");
startActivity(Intent.createChooser(intent, "Share via"));
** its possible Check out below which shows the filteration for Facebook,Gmail,Twitter.**
Updated to Share Text + Image:
Select the image from the SDCard:
String fileName = "image-3116.jpg";
String externalStorageDirectory =
Environment.getExternalStorageDirectory().toString();
String myDir = externalStorageDirectory + "/saved_images/"; // the
// file will be in saved_images
Uri uri = Uri.parse("file:///" + myDir + fileName);
enter code here
Share via Twitter
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
(String)v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String)
v.getTag(R.drawable.ic_launcher));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
PackageManager pm = v.getContext().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);
v.getContext().startActivity(shareIntent);
break;
}
}
Share via Facebook
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String)
v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String)
v.getTag(R.drawable.ic_launcher));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
PackageManager pm = v.getContext().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);
v.getContext().startActivity(shareIntent);
break;
}
}
Share via Gmail
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String)
v.getTag(R.string.app_name));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String)
v.getTag(R.drawable.ic_launcher));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
PackageManager pm = v.getContext().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);
v.getContext().startActivity(shareIntent);
break;
}
}
It's ok, I changed my code for :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem item = menu.findItem(R.id.file);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
mShareActionProvider.setOnShareTargetSelectedListener(this);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
openShare();
return false;
}
});
return true;
}
private void openShare() {
Resources resources = getResources();
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));
emailIntent.setType("message/rfc822");
PackageManager pm = getPackageManager();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));
List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if(packageName.contains("android.email")) {
emailIntent.setPackage(packageName);
} else if(packageName.contains("twitter") || packageName.contains("facebook") || packageName.contains("mms") || packageName.contains("android.gm")) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if(packageName.contains("twitter")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_twitter));
} else if(packageName.contains("facebook")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_facebook));
} else if(packageName.contains("mms")) {
intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_sms));
} else if(packageName.contains("android.gm")) {
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
intent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));
intent.setType("message/rfc822");
}
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);
startActivity(openInChooser);
}
But I need to custom BackgroundColor :-)

how can PutExtra EXTRA_EMAIL for Action_send?

I have code that filter specific apps for ACTION_SEND intent.
But I can not set for gmail and mail EXTRA_EMAIL.
I try for this:
String packageName = ri.activityInfo.packageName;
if(packageName.contains("email"))
{
emailIntent.setPackage(packageName);
}
else if( packageName.contains("android.gm") || packageName.contains("mail"))
{
Intent intent = new Intent();
intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
if(packageName.contains("android.gm")) {
intent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));
intent.putExtra(Intent.EXTRA_EMAIL,"boghche.app#gmail.com");
The EXTRA_EMAIL extra requires an array of String. Use the String Array constructor
Intent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "boghche.app#gmail.com" });
You need to check this way.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "urSubject");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "ExtraText");
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList)
{
if ((app.activityInfo.name).contains("gmail"))
{
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);
v.getContext().startActivity(shareIntent);
break;
}
}
final Intent intent = new Intent(
android.content.Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"subject name");
intent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.fromFile(new File(file.toString())));
final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(
intent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm")
|| info.activityInfo.name.toLowerCase()
.contains("gmail"))
best = info;
if (best != null)
intent.setClassName(best.activityInfo.packageName,
best.activityInfo.name);
startActivity(intent);

Categories

Resources