Android获取分享应用列表详解及实例
如果在应用的AndroidManifest.xml中含有 ACTION_SEND 属性,那就证明该应用可以供第三方应用进行调用分享,那怎么获取函数该属性的分享列表了,这对我们做应用的非常有用;最近在做该功能,自己也做了下自定义的分享列表,用PopupWindow的方式弹出。
1、布局:
popup_share.xml
popup_share_item.xml
2、查询手机内所有支持分享的应用列表
public ListgetShareApps(Context context) { List mApps = new ArrayList (); Intent intent = new Intent(Intent.ACTION_SEND, null); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("text/plain"); // intent.setType("**"); //这里就是组织内容了, shareIntent.putExtra(Intent.EXTRA_TEXT, "test"); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); DetailExchangeActivity.this.startActivity(shareIntent); } }); sharePopupWindow = new PopupWindow(view, (int)(160 * density), LinearLayout.LayoutParams.WRAP_CONTENT); } //使其聚焦 sharePopupWindow.setFocusable(true); //设置允许在外点击消失 sharePopupWindow.setOutsideTouchable(true); // 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景 sharePopupWindow.setBackgroundDrawable(new BitmapDrawable()); //xoff,yoff基于anchor的左下角进行偏移。正数表示下方右边,负数表示(上方左边) //showAsDropDown(parent, xPos, yPos); sharePopupWindow.showAsDropDown(parent, -5, 5); }
注:ShareCustomAdapter自己建一个就行了。(显示会有一个图标和一个分享的名字)
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!



