android 簡單的分享方法

weixin_34162629發表於2012-07-20

除了使用oauth認證然後呼叫各大平臺的介面分享外還有一種簡單的方法可以實現分享功能。

缺點是需要使用者手機上已經安裝了那些客戶端

    Intent intent=new Intent(Intent.ACTION_SEND);  
    intent.setType("text/plain");  //純文字

    /*圖片分享

    it.setType("image/png");

     //新增圖片
     File f = new File(Environment.getExternalStorageDirectory()
       +"/Pictures/2.png");
     Uri u = Uri.fromFile(f);
     it.putExtra(Intent.EXTRA_STREAM, u);

     */
    intent.putExtra(Intent.EXTRA_SUBJECT, "分享");  
    intent.putExtra(Intent.EXTRA_TEXT, "I would like to share this with you...");  
    startActivity(Intent.createChooser(intent, getTitle()));  

相關文章