2013-09-21 133 views
0

我嘗試使用ShareActionProvider(support.v7)爲我的應用執行共享。所有的應用程序,如Gmail,Evernote等。 al,工作很好 - 除了Facebook。我不知道問題是什麼。這裏是我的一小段代碼片段:Android ShareActionProvider未能分享到Facebook

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.share, menu); 
    MenuItem shareItem = menu.findItem(R.id.action_share); 
    mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem); 
    mShareActionProvider.setShareIntent(shareIntent()); 

    return true; 
} 

public Intent shareIntent() { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("type/plain"); 
    shareIntent.setType("image/*"); 
    shareIntent.putExtra(Intent.EXTRA_SUBJECT,"SUBJECT"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT,"TEXT TEXT"); 
    return shareIntent; 
} 

回答

4

首先,不叫setType()兩次,因爲第二個將替換第一個。其他type/plain不是有效的MIME類型。嘗試text/plain

三,如果您打算使用image/*,您需要使用EXTRA_STREAM來提供圖像。

+0

非常感謝,你救了我一個小時!關於將圖片分享到Facebook,我可以使用外部鏈接,如「http://www.abc.com/abc.png」嗎? – user2761885

+1

@ user2761885:通常共享是針對本地內容的。我不能說Facebook是否支持這種方式共享鏈接。 – CommonsWare

+0

非常感謝!!!!!!! – user2761885