Android之Action_SEND小例子

來源:互聯網
上載者:User

標籤:android開發

     我們知道在Android中系統有很多內建的ACTION(動作/活動),通過Intent中添加ACTION資訊,可以實現很多系統功能,如開啟相簿,拍照,發資訊等。在工作中,經常用到ACTION_SEND這個ACTION,就做個小小的總結,記錄下來。

   1,發郵件:

Uri uri= Uri.parse("content://media/external/images/media/23");
Intent intent= new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "shenrenkui");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");

startActivity(intent)

2,發多媒體訊息:

Uri uri = Uri.parse("content://media/external/images/media/23");
Intent intent = new Intent(Intent.ACTION_SEND);
intent .putExtra("sms_body", "我的資訊");
intent .putExtra(Intent.EXTRA_STREAM, uri);
intent .setType("image/png");

接下來是今天主要講的小功能,就是分享功能的實現,我們可以通過ACTION_SEND實現分享功能,調用起手機中裝有分享的軟體,並分享我們的資訊出去。

/**分享的intent*/  
Intent intent = new Intent(Intent.ACTION_SEND);  
 /**分享的資料類型  */
 intent.setType("text/plain");  
/**分享的主題(標題) */
intent.putExtra(Intent.EXTRA_SUBJECT, "好友分享");  
 /**內容*/  
 intent.putExtra(Intent.EXTRA_TEXT, "我正在使用快點碼,你也加入吧!!");  
 /**允許啟動新的Activity */ 
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
 /**目標應用尋找對話方塊的標題  */
startActivity(Intent.createChooser(intent, "標題"));  

這樣就會調用起相應的分享應用,比如簡訊,電子郵件等。

Android之Action_SEND小例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.