Android 自定义分享列表ACTION_SEND
来源:互联网 发布:炒外汇技术大数据 编辑:程序博客网 时间:2024/06/06 02:45
看到最近都在做自定义的东西,因为比较灵活,还可以摆脱系统自身不怎么漂亮的UI,(大家都懂得)所以自己也做了下自定义的分享列表,用PopupWindow的方式弹出。
先上效果图:
1、布局:
popup_share.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent" android:layout_height="wrap_content" > <ListView android:id="@+id/share_list" android:background="#2F4F4F" android:fadingEdge="none" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cacheColorHint="#00000000" android:divider="#E2DD75" android:dividerHeight="1.0dip" android:headerDividersEnabled="true" android:footerDividersEnabled="false" /></LinearLayout>popup_share_item.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="2.0dip" ><ImageView android:id="@+id/share_item_icon" android:layout_width="32.0dip" android:layout_height="32.0dip" android:layout_marginLeft="3.0dip" android:scaleType="fitXY" /><TextView android:id="@+id/share_item_name" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="分享" android:textColor="@color/white" android:singleLine="true" android:textSize="@dimen/s_size" android:layout_marginLeft="3.0dip" android:layout_marginRight="3.0dip" /></LinearLayout>
2、查询手机内所有支持分享的应用列表
public List<ResolveInfo> getShareApps(Context context) {List<ResolveInfo> mApps = new ArrayList<ResolveInfo>();Intent intent = new Intent(Intent.ACTION_SEND, null);intent.addCategory(Intent.CATEGORY_DEFAULT);intent.setType("text/plain");//intent.setType("*/*");PackageManager pManager = context.getPackageManager();mApps = pManager.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);return mApps;}注:ApplicationInfo是从一个特定的应用得到的信息。这些信息是从相对应的Androdimanifest.xml的< application>标签中收集到的。
ResolveInfo这个类是通过解析一个与IntentFilter相对应的intent得到的信息。它部分地对应于从AndroidManifest.xml的< intent>标签收集到的信息。
得到List列表,我自建的AppInfo类,自己建一个就行
private List<AppInfo> getShareAppList() {List<AppInfo> shareAppInfos = new ArrayList<AppInfo>();PackageManager packageManager = getPackageManager();List<ResolveInfo> resolveInfos = getShareApps(mContext);if (null == resolveInfos) {return null;} else {for (ResolveInfo resolveInfo : resolveInfos) {AppInfo appInfo = new AppInfo();appInfo.setAppPkgName(resolveInfo.activityInfo.packageName);//showLog_I(TAG, "pkg>" + resolveInfo.activityInfo.packageName + ";name>" + resolveInfo.activityInfo.name);appInfo.setAppLauncherClassName(resolveInfo.activityInfo.name);appInfo.setAppName(resolveInfo.loadLabel(packageManager).toString());appInfo.setAppIcon(resolveInfo.loadIcon(packageManager));shareAppInfos.add(appInfo);}}return shareAppInfos;}3、弹出PopupWindow的实现
参考地址:
PackageInfo、ResolveInfo
- Android 自定义分享列表ACTION_SEND
- Android 自定义分享列表ACTION_SEND
- Android 自定义分享列表ACTION_SEND
- Android分享之Intent.ACTION_SEND分享(一)
- Android分享之Intent.ACTION_SEND分享(二)
- android利用Intent.ACTION_SEND实现简单分享功能
- Intent.ACTION_SEND分享程序过滤
- 用Intent.ACTION_SEND进行分享
- 利用Intent.ACTION_SEND进行分享
- 利用Intent.ACTION_SEND进行分享
- 利用Intent.ACTION_SEND进行分享
- android 使用Intent.ACTION_SEND分享图片和文字内容(新浪微博,短信等)
- Android之Action_SEND小例子
- Android中的ACTION_SEND与ShareCompat
- Android:新浪微博拉起客户端分享——完美实现同时分享图片和文字(Intent.ACTION_SEND)
- 完美实现同时分享图片和文字(Intent.ACTION_SEND)
- 完美实现同时分享图片和文字(Intent.ACTION_SEND)
- 完美实现同时分享图片和文字(Intent.ACTION_SEND)
- wordpress press 找回admin密码,并且固定密码
- Windows程序调试----第一部分 调试策略----第4章 使用跟踪语句
- 网页游戏加速浏览器的原理是什么?
- 黑马程序员-IO流 字符流与字节流
- Boost1.53在vs2008下的配置
- Android 自定义分享列表ACTION_SEND
- 学生信息管理系统
- Studio for WPF 和 Silverlight 本地化, Localization, Localización, Lokalisering
- NDK in cocos2d-x
- C语言解释器-5 类型系统
- file mime 类型表
- 读取excel到对象
- ldap迁移脚本group
- 商场家电库存模型