android 分享
来源:互联网 发布:潘多拉优化网络软转发 编辑:程序博客网 时间:2024/06/05 05:50
http://www.cnblogs.com/feng88724/archive/2011/02/01/1961227.html
本讲主要介绍如何在自己的应用中实现分享功能,同时介绍如何将自己的程序加入分享列表。
比如有一张图片,想要分享到校内上...看看效果图吧。
本次我们就是要做这样的效果,同时把自己的应用也加入到分享列表中。
调出"共享方式"的代码如下:
Intent intent=new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, "好东西,与您分享!"); startActivity(Intent.createChooser(intent, getTitle()));
如何让自己的应用也加入这个分享列表呢?
答案其实也很简单,只需在AndroidManifest.xml配置文件中activity标签之间加入以下代码:
<intent-filter><action android:name="android.intent.action.SEND"></action><category android:name="android.intent.category.DEFAULT"></category><data android:mimeType="text/plain"></data></intent-filter>
注意,以上程序最好在真机上测试,模拟器上看不出效果!
另外,有的同学可能不想把这些应用都显示出来,比如指向要短信、邮件,那么可以通过先获取分享列表,然后自己过滤的方式来实现。
获取分享列表代码:
public List<ResolveInfo> getShareTargets(){ List<ResolveInfo> mApps = new ArrayList<ResolveInfo>(); Intent intent=new Intent(Intent.ACTION_SEND,null); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("text/plain"); PackageManager pm=this.getPackageManager(); mApps=pm.queryIntentActivities(intent,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); return mApps; }
- 【Android】分享
- android分享
- android 分享
- android 分享
- android 分享
- Android分享
- Android分享
- Android 分享
- android分享支付经验分享
- Android的Ril分享
- Android模拟器介绍 分享
- Android蓝牙经验分享
- 分享一些android题目
- Android学习资料分享
- Android PowerManager.WakeLock分享
- Android 分享功能
- android 使用分享功能
- Android开发资料分享
- NSInvocation简单使用
- qt对话框不在任务栏显示
- ExtJs4_AdvancedValidation示例;
- 对泛型集合进行筛选
- 在insert中使用子查询
- android 分享
- 从 Java 档案 (JAR) 中读取文件
- [转]烦人的BeforePropertie----BeforeProperties,AfterProperties,properties.ListItem
- ExtJs4_BindingGridToForm示例浅谈;
- Boost.Interprocess使用手册翻译之十一:所有权的智能指针(Ownership smart pointers)
- TCP/IP详解学习笔记(1)-基本概念
- MS SQL Server 2000 数据库使用备份还原造成dbo登录名丢失解决法(转)
- hadoop学习笔记(2) 伪分布模式配置
- 修改oracle管理平台占用的8080端口