Android系統內建分享功能的實現(可同一時候分享文字和圖片)

來源:互聯網
上載者:User

標籤:ext   har   ring   echo   分享圖片   mod   androi   share   param   



/**      * 分享功能      *       * @param context      *            上下文      * @param activityTitle      *            Activity的名字     * @param msgTitle      *            訊息標題      * @param msgText     *            訊息內容      * @param imgPath      *            圖片路徑,不分享圖片則傳null      */      public void shareMsg(String activityTitle, String msgTitle, String msgText,              String imgPath) {          Intent intent = new Intent(Intent.ACTION_SEND);          if (imgPath == null || imgPath.equals("")) {              intent.setType("text/plain"); // 純文字          } else {              File f = new File(imgPath);              if (f != null && f.exists() && f.isFile()) {                  intent.setType("image/jpg");                Uri u = Uri.fromFile(f);                  intent.putExtra(Intent.EXTRA_STREAM, u);              }          }          intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle);          intent.putExtra(Intent.EXTRA_TEXT, msgText);          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);          startActivity(Intent.createChooser(intent, activityTitle));      }  
簡單,直接使用!

Android系統內建分享功能的實現(可同一時候分享文字和圖片)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.