功能比較簡單,代碼也極少。應該也很實用吧。
效果圖:
(1)分享純文本
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");//純文本
intent.putExtra(Intent.EXTRA_TEXT,"這裏是分享的純文本");
startActivity(Intent.createChooser(intent,"分享文本"));
(2)分享圖片
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/jpeg");//圖片
File image = new File(Environment.getExternalStorageDirectory().getPath()+"/DCIM/Screenshots/lock_wallpaper.jpg");
Uri uri = Uri.fromFile(image);//圖片路徑
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent,"分享圖片"));
把代碼片段拷入“分享按鈕”的點擊事件即可。注意替換掉文本內容和圖片的路徑。
--------------------------------------------------------------------------------------------------------------------
說明:菜鳥,第一次寫博客,希望輕噴。我有一張學生卡,滴!!!老司機等等我......................