如何在android开发使用ACTION_SEND中共享图片和文本

我想使用 ACTION_SEND 共享图片+文字,我运行了下面的代码,暂时只能共享图片,无法共享文字,我如何才能共享?

[java]  view plain copy
 
  1. private Uri imageUri;  
  2.        private Intent intent;  
  3.    
  4.         imageUri = Uri.parse("android.resource://" + getPackageName()  
  5.                 + "/drawable/" + "ic_launcher");  
  6.         intent = new Intent();  
  7.         intent.setAction(Intent.ACTION_SEND);  
  8.         intent.putExtra(Intent.EXTRA_TEXT, "Hello");  
  9.         intent.putExtra(Intent.EXTRA_STREAM, imageUri);  
  10.         intent.setType("image/*");  
  11.         startActivity(intent);  


 

//如何才能共享图片?

处理方法

你可以共享下面的代码:

String shareBody = "Here is the share content body";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));

所以你的全部代码(图片+文本)需要变成

 
[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. private Uri imageUri;  
  2. private Intent intent;  
  3.    
  4. imageUri = Uri.parse("android.resource://" + getPackageName()  
  5. "/drawable/" + "ic_launcher");  
  6.    
  7. intent = new Intent(Intent.ACTION_SEND);  
  8. //text  
  9. intent.putExtra(Intent.EXTRA_TEXT, "Hello");  
  10. //image  
  11. intent.putExtra(Intent.EXTRA_STREAM, imageUri);  
  12. //type of things  
  13. intent.setType("*/*");  
  14. //sending  
  15. startActivity(intent);  


把image/*替换成 with */*

更新:

 
[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. Uri imageUri = Uri.parse("android.resource://" + getPackageName()  
  2. "/drawable/" + "ic_launcher");  
  3. Intent shareIntent = new Intent();  
  4. shareIntent.setAction(Intent.ACTION_SEND);  
  5. shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");  
  6. shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);  
  7. shareIntent.setType("image/jpeg");  
  8. shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);  
  9. startActivity(Intent.createChooser(shareIntent, "send"));  


原文地址:http://www.itmmd.com/201411/214.html 
该文章由 萌萌的IT人 整理发布,转载须标明出处。

猜你喜欢

转载自aijuans.iteye.com/blog/2170446
今日推荐