简体   繁体   English

Android ACTION_SEND意图和Google Analytics - 我怎么知道他们选择了什么?

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

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. 我们正在使用Google Analytics跟踪我们正在使用的应用程序的哪些功能以及如何使用,但此问题也适用于您想要在调用ACTION_SEND意图后了解用户所执行操作的任何情况。

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. 基本上,我想使用此功能允许用户共享内容(电子邮件,Twitter,Facebook等)。这非常有效地使用股票Android Intent功能,允许用户选择他们喜欢的电子邮件客户端,Twitter应用程序等。

        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. 但是,我无法找到任何方法来了解用户从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. 我考虑使用startActivityForResult ,但这似乎只返回它们是否完成或取消共享(甚至在不同的应用程序中似乎不一致地实现) - 它当然不会给我任何关于它们所做的信息。

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? 在这一点上,看起来为了获得我的分析,我将不得不使用我自己和他们各自的SDK的自定义操作通过Facebook和Twitter实现共享?

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.... 这似乎是一种耻辱,因为它破坏了Android的一个很好的功能 - 能够使用您首选的电子邮件,Twitter,Facebook和浏览器应用程序....

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. 如果您要自己创建意图选择列表,而不是允许Intent.createChooser为您执行此操作,您可以在自己执行之前查看选择了哪个意图。

Here is how Gallery3D does it , from the Android source code. 以下是Gallery3D如何使用Android源代码。 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. 它向包管理器查询与您要求运行的Intent匹配的包,并返回一个ResolveInfo列表,您可以使用该列表向用户显示他们的选择,然后记录他们的选择并使用他们的选择启动Activity。

How about reading from the Android logs? 从Android日志中读取怎么样? I expect the logs contain details of what they selected. 我希望日志包含他们所选内容的详细信息。 Ugly, but it might work. 丑陋,但它可能会奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM