现在的位置: 首页 > 综合 > 正文

分享图片

2016年12月04日 ⁄ 综合 ⁄ 共 748字 ⁄ 字号 评论关闭

Intent intent = new Intent(Intent.ACTION_SEND);

intent.setType("image/*");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, "分享的内容");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Bitmap bm = BitmapFactory.decodeResource(this.getResources(),
R.drawable.share_logo);//1.从工程的drawable-hdpi目录下获得图片

try {
FileOutputStream Os = this.openFileOutput("share_logo.png",
Context.MODE_WORLD_READABLE);
bm.compress(Bitmap.CompressFormat.JPEG, 100, Os);
//2. 把图片先保存在files目录里
Os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

File f = this.getFileStreamPath("share_logo.png");//3.从files目录里获得图片
Uri u = Uri.fromFile(f);

                       intent.putExtra(Intent.EXTRA_STREAM, u);

                       startActivity(intent);//4.最后发送

抱歉!评论已关闭.