Android 信息分享實現

一、短信分享

01
Intent intent = new Intent(Intent.ACTION_SEND);
02
// intent.setType("text/plain"); //純文本
03
// 圖片分享
04
intent.setType("image/png");
05
// 添加圖片
06
File f = new File("/sdcard/sd.png");
07
Uri u = Uri.fromFile(f);
08
intent.putExtra(Intent.EXTRA_STREAM, u); //添加圖片
09
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
10
intent.putExtra(Intent.EXTRA_TEXT, "I would like to share this with you…");
11
startActivity(Intent.createChooser(intent, getTitle()));
二、郵件分享
 
01
Intent log = new Intent("android.intent.action.SEND");
02
Object[] arrayOfObject2 = new Object[3];
03
arrayOfObject2[0] = "nick";
04
arrayOfObject2[1] = ": ";
05
arrayOfObject2[2] = "content";
06
String str1 = String.format("@%s%s %s", arrayOfObject2);
07
String str2 = str1 + "什麼";
08
Object[] arrayOfObject1 = new Object[1];
09
arrayOfObject1[0] = str2;
10
log.putExtra("android.intent.extra.TEXT", getString(R.string.mail_body_text, arrayOfObject1));
11
log.putExtra("android.intent.extra.SUBJECT", "郵件");
12
log.setType("application/octet-stream");
13
startActivity(log);

作者:android.google

發佈留言