检测用于共享某些内容的共享者

时间:2012-09-26 10:20:22

标签: android android-intent broadcastreceiver share intentfilter

在我正在处理的应用程序中,我需要知道用户为了统计目的而共享内容以记录内容的“ACTION_SEND sharer”(Twitter,Facebook,SMS,Email ...)。反正有吗?

我有一些想法,其中一个是修改那些共享者的目标Intent指向接收共享者选择的接收者Intent,用这些数据做我们需要的任何事情,然后调用最终的Intent到目标共享者(Twitter,Facebook,短信,电子邮件......)。对于最后一步,我想我需要知道每个目标应用程序的共享操作。

此致

UPDATE1

为了说明,我分享了我目前用来共享内容的方法,根据目标共享者自定义Intent附加功能:

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

解决

关注此链接上的指示:http://goo.gl/hf8Kg

1 个答案:

答案 0 :(得分:1)

  

有没有这样做?

您可以通过PackageManagerqueryIntentActivities()显示自己的选择器对话框。