Android ACTION_SEND Intent and Google Analytics - how do I know what they picked?

1.2k views Asked by At

We are using Google Analytics to track what features of our application are being used and how, but this question could also apply to any situation where you want to know what a user did after calling the ACTION_SEND Intent.

Basically, I want to use this functionality to allow users to share content (Email, Twitter, Facebook, etc.) This works wonderfully using the stock Android Intent functionality, allowing the user to pick their preferred email client, twitter app, ect.

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        //Text seems to be necessary for Facebook and Twitter
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, "whatever I want to share");
        startActivity(Intent.createChooser(sharingIntent,"Share using"));

However, I can't find any way to know what the user did upon return from the Intent. I looked into using startActivityForResult instead, but this seems to only return whether or not they completed or canceled sharing (and even that seems inconsistently implemented across different applications) - it certainly doesn't give me any information on what they did.

At this point, it looks like in order to have my analytics, I would have to implement sharing via Facebook and Twitter using custom actions of my own and their respective SDKs?

This seems a shame since it undermines one of the nice features of Android - being able to use your preferred Email, Twitter, Facebook and Browser applications....

2

There are 2 answers

0
Ollie C On

How about reading from the Android logs? I expect the logs contain details of what they selected. Ugly, but it might work.

2
Jess On

If you were to create the intent selection list yourself, instead of allowing Intent.createChooser to do it for you, you could see which intent was selected before executing it yourself.

Here is how Gallery3D does it, from the Android source code. It queries the package manager for packages that match the Intent you're asking to run and returns a list of ResolveInfo that you can use to present the user their choices, then record their choice and start the Activity with their selection.