2014-03-06 36 views
2

我正在從事在線教程中的分享功能,我找到了示例代碼並創建了這樣的功能。但它也有一些缺點(還有,如果我安裝了很多應用程序的太多選項),等等,總之,我想做到以下幾點:如何在android中創建「一般」共享意圖?

  1. 嚴格的選項影的Gmail
  2. 如何分享圖像(如果我爲它提供的鏈接?(微博似乎接受純文本格式))
  3. 下面的代碼顯示沒有在Facebook的應用程序?(不能在Facebook上共享數據)

這裏是我的代碼:

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
       sendIntent.setType("text/plain"); 
       try { 
        String newsUrl = Html.fromHtml(URLDecoder.decode(content[0], "UTF-8")).toString().replace("appfunc://share=", ""); 
        String title = Html.fromHtml(URLDecoder.decode(content[1], "UTF-8")).toString(); 
        String newsContent = Html.fromHtml(URLDecoder.decode(content[2], "UTF-8")).toString(); 
        if (!newsContent.equals("")) 
         newsContent += "...\n\n"; 
        sendIntent.putExtra(Intent.EXTRA_TEXT, title + "\n\n" + newsContent + ctx.getResources().getString(R.string.link) + ": " + newsUrl); 
       } catch (UnsupportedEncodingException e) { 
        // TODO Auto-generated catch block 
        sendIntent.putExtra(Intent.EXTRA_TEXT, ctx.getResources().getString(R.string.share_placeholder)); 
        e.printStackTrace(); 
       }; 
       ctx.startActivity(Intent.createChooser(sendIntent, ctx.getResources().getString(R.string.share_to))); 
+0

Facebook [不支持預填寫帖子](https://developers.facebook.com/x/bugs/332619626816423/)。 – mgorven

+0

是否有可能不使用他們的SDK來實現Facebook共享?謝謝 – user782104

回答

2

您可以共享使用shareIntent相似圖片

private Intent createShareIntent() 
{ 
    shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setType("image/*"); 
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+CreateTempFile(bitmapImage))); 
    return shareIntent; 
} 
private File CreateTempFile(Bitmap myBitmap) 
{ 

    try 
    { 
    File SharingFile = File.createTempFile("OriginalImage", ".jpeg",temporaryFile); 
     FileOutputStream out = new FileOutputStream(SharingFile); 
     myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); 
     out.flush(); 
     out.close(); 

    } 
    catch (IOException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 


return SharingFile; 

} 

做這樣的事情,這將打開會接受你的形象所有的應用程序。

+0

感謝您的幫助 – user782104