In the application I'm currently working on I need to know what "ACTION_SEND sharer" (Twitter, Facebook, SMS, Email...) the user used to share a content to log it for statistic purposes. Is there anyway to do that?
I have some ideas, one of those is to modify the target Intent of those sharers to point to a receiver Intent that would receive the sharer choosen, do whatever we need with this data and then invoke a final Intent to the target sharer (Twitter, Facebook, SMS, Email...). For this final step, I suppose I need to know the share Action of each target application.
Regards
UPDATE1
To ilustrate, I share the method I'm currently using to share a content, customizing the Intent extras depending on the target sharer:
private void shareItem(String title, String link) {
// Standard message to send
String msg = title + " " + link;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent targetedShareIntent = null;
for (ResolveInfo resolveInfo : resInfo) {
String packageName = resolveInfo.activityInfo.packageName;
targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
// Find twitter: com.twitter.android...
if ("com.twitter.android".equals(packageName)) {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg);
} else if ("com.google.android.gm".equals(packageName)) {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Uri.encode(title + "\r\n" + link));
} else if ("com.android.email".equals(packageName)) {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Uri.encode(title + "\n" + link));
} else {
// Rest of Apps
targetedShareIntent.putExtra( android.content.Intent.EXTRA_TEXT, msg);
}
targetedShareIntent.setPackage(packageName);
targetedShareIntents.add(targetedShareIntent);
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), getResources().getString(R.string.share));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));
startActivityForResult(chooserIntent, 0);
}
}
Is there anyway to do that?
You can display your own chooser dialog, by means of PackageManager
and queryIntentActivities()
.