【问题标题】:facebook share doesn't work, when click share from the action bar从操作栏中单击共享时,Facebook 共享不起作用
【发布时间】:2014-03-13 18:28:33
【问题描述】:

我使用下面的代码在操作栏中放置了一个分享按钮,以便分享特定的文本。当我单击共享时,它适用于消息传递和电子邮件等,但当我单击 Facebook 时。 Facebook 在创建状态位上打开,尽管我下面代码中的共享文本不存在。

我做错了什么?或者有什么我需要添加或更改的吗?

XML:

 <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:id="@+id/menu_item_share"
            android:showAsAction="ifRoom"
            android:title="Share"
            android:actionProviderClass="android.widget.ShareActionProvider" />
    </menu>

ActivityMain:

   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.action_bar_share_menu, menu);
        MenuItem item = menu.findItem(R.id.menu_item_share);
        ShareActionProvider myShareActionProvider = (ShareActionProvider) item.getActionProvider();
        Intent myIntent = new Intent();
        myIntent.setAction(Intent.ACTION_SEND);
        myIntent.putExtra(Intent.EXTRA_TEXT, "Whatever message you want to share");
        myIntent.setType("text/plain");
        myShareActionProvider.setShareIntent(myIntent);
        return true;
    }

【问题讨论】:

    标签: android xml facebook android-activity android-actionbar


    【解决方案1】:

    Facebook 可能正在寻找 EXTRA_SUBJECT。

    在 FB 上未经测试的巨魔太多。

    private Intent createShareIntent() {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        String s = getString(R.string.shareText);
        shareIntent.putExtra(Intent.EXTRA_TEXT, s);
        s = getString(R.string.sharesubject);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, s);
        return shareIntent;
    }
    

    使用 appcompat 操作栏。

        MenuItem menuItem = menu.findItem(R.id.menu_item_share);
    
        // Fetch and store ShareActionProvider
        mShareActionProvider = (ShareActionProvider) MenuItemCompat
                .getActionProvider(menuItem);
    
        mShareActionProvider.setShareIntent(createShareIntent());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多