Discover the recipient used to share some content

In the application in which I am currently working, I need to know that the "ACTION_SEND sharer" (Twitter, Facebook, SMS, email ...) was used by the user to share content for registration for statistical purposes. Is there any way to do this?

I have some ideas, one of which is to change the target intent of these participants, to indicate the recipient’s intention, which would get the elector, do everything we need with this data, and then call the final intention to the target participant (Twitter, Facebook, SMS, email ...). For this last step, I suppose I need to know the stock action of each target application.

Hello

Update1

To show the illustration, I use the method that I use now to share content, setting up the Intent add-ons depending on the target participant:

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); } } 

solvable

Follow the directions at this link: http://goo.gl/hf8Kg

+4
source share
1 answer

Is there any way to do this?

You can display your own selection dialog using PackageManager and queryIntentActivities() .

+1
source

Source: https://habr.com/ru/post/1436342/


All Articles