Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Android Intent.ACTION_SEND

I'm using Intent for sharing url and subject. In this intent filter showing all the sharing apps. i want only (facebook/gmail/message/skype/twitter) these option in popup. is this possible to customize sharing intent filter.

 Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);  sharingIntent.setType("text/plain");  String shareBody = adapter.getDetails("url";  sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"subject");  sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);  startActivity(Intent.createChooser(sharingIntent, "Share via")); 

thanks

like image 306
Jeeva123 Avatar asked Nov 16 '13 06:11

Jeeva123


People also ask

How do I set extras Intent?

Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.

What is the use of Intent createChooser () method?

Most commonly, ACTION_SEND action sends URL of build-in Browser app. While sharing the data, Intent call createChooser() method which takes Intent object and specify the title of the chooser dialog. Intent. createChooser() method allows to display the chooser.

What is custom Intent in android?

Custom intents also have intent parameters, which you can map to parameters in your corresponding fulfillment. Unlike BIIs, custom intents require query patterns to describe example queries that a user might say. This approach differs from built-in intents, which each model common ways that users express that intent.

What is Intent setType in android?

setType(String mimeType) input param is represent the MIME type data that u want to get in return from firing intent(here myIntent instance). by using one of following MIME type you can force user to pick option which you desire. Please take a Note here, All MIME types in android are in lowercase.


1 Answers

Yes, 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); 

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).startsWith("com.facebook.katana"))           {            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;            }        } 

Share via WhatsApp:

 Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/html"); 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("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);                         v.getContext().startActivity(shareIntent);                         break;                     }                 } 
like image 95
GrIsHu Avatar answered Sep 20 '22 17:09

GrIsHu