为了账号安全,请及时绑定邮箱和手机立即绑定

Android和Facebook共享意图

Android和Facebook共享意图

慕的地6264312 2019-07-09 12:51:40
Android和Facebook共享意图我正在开发一个Android应用程序,我想知道如何使用Android的共享意图从应用程序内部更新应用程序用户的状态。在浏览了Facebook的SDK之后,看起来这很容易做到,但是我很想让用户通过常规的共享意图弹出窗口来做这件事?见此:我已经尝试了通常的共享意图代码,但这似乎不再适用于Facebook。public void invokeShare(Activity activity, String quote, String credit) {     Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);     shareIntent.setType("text/plain");     shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, activity.getString(R.string.share_subject));     shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text");         activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.share_title)));}更新:在做了更多的调查之后,它看起来像是Facebook应用程序中的一个尚未解决的bug!Facebook bug)同时,看起来我不得不忍受负面的“分享不起作用!”评论。干杯Facebook:*(
查看完整描述

3 回答

?
慕容森

TA贡献1853条经验 获得超18个赞

通常的方式

创建所需内容的通常方法是简单地执行以下操作:

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, "The status update text");
    startActivity(Intent.createChooser(intent, "Dialog title text"));

这对我来说没有任何问题。

另一种方法(也许)

这样做的潜在问题是,您还允许通过电子邮件、SMS等发送消息。下面的代码是我在应用程序中使用的,它允许用户使用Gmail发送电子邮件。我猜你可以尝试改变它,使它只适用于Facebook。

我不确定它是如何对任何错误或异常做出反应的(我猜如果没有安装Facebook,就会发生这种情况),所以您可能需要对其进行一些测试。

    try {
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        String[] recipients = new String[]{"e-mail address"};
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "E-mail subject");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "E-mail text");
        emailIntent.setType("plain/text"); // This is incorrect MIME, but Gmail is one of the only apps that responds to it - this might need to be replaced with text/plain for Facebook
        final PackageManager pm = getPackageManager();
        final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
        ResolveInfo best = null;
        for (final ResolveInfo info : matches)
            if (info.activityInfo.packageName.endsWith(".gm") ||
                    info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
                if (best != null)
                    emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
                startActivity(emailIntent);
    } catch (Exception e) {
        Toast.makeText(this, "Application not found", Toast.LENGTH_SHORT).show();
    }


查看完整回答
反对 回复 2019-07-09
  • 3 回答
  • 0 关注
  • 333 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信