分享應(yīng)用列表怎么在Android應(yīng)用中獲?。肯嘈藕芏鄾](méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
創(chuàng)新互聯(lián)建站專(zhuān)業(yè)網(wǎng)站設(shè)計(jì)制作、網(wǎng)站建設(shè),集網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、網(wǎng)站制作于一體,網(wǎng)站seo、網(wǎng)站優(yōu)化、網(wǎng)站營(yíng)銷(xiāo)、軟文營(yíng)銷(xiāo)等專(zhuān)業(yè)人才根據(jù)搜索規(guī)律編程設(shè)計(jì),讓網(wǎng)站在運(yùn)行后,在搜索中有好的表現(xiàn),專(zhuān)業(yè)設(shè)計(jì)制作為您帶來(lái)效益的網(wǎng)站!讓網(wǎng)站建設(shè)為您創(chuàng)造效益。
Android獲取分享應(yīng)用列表
1、布局:
popup_share.xml
<?xml version="1.0" encoding="utf-8"?>
popup_share_item.xml
<?xml version="1.0" encoding="utf-8"?>
2、查詢(xún)手機(jī)內(nèi)所有支持分享的應(yīng)用列表
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("*/*"); PackageManager pManager = context.getPackageManager(); mApps = pManager.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); return mApps; }
注:ApplicationInfo是從一個(gè)特定的應(yīng)用得到的信息。這些信息是從相對(duì)應(yīng)的Androdimanifest.xml的< application>標(biāo)簽中收集到的。
ResolveInfo這個(gè)類(lèi)是通過(guò)解析一個(gè)與IntentFilter相對(duì)應(yīng)的intent得到的信息。它部分地對(duì)應(yīng)于從AndroidManifest.xml的< intent>標(biāo)簽收集到的信息。
得到List列表,我自建的AppInfo類(lèi),自己建一個(gè)就行
private ListgetShareAppList() { List shareAppInfos = new ArrayList (); PackageManager packageManager = getPackageManager(); List 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的實(shí)現(xiàn)
private void initSharePopupWindow(View parent) { PopupWindow sharePopupWindow = null; View view = null; ListView shareList = null; if(null == sharePopupWindow) { //加載布局文件 view = LayoutInflater.from(DetailExchangeActivity.this).inflate(R.layout.popup_share, null); shareList = (ListView) view.findViewById(R.id.share_list); ListshareAppInfos = getShareAppList(); final ShareCustomAdapter adapter = new ShareCustomAdapter(mContext, shareAppInfos); shareList.setAdapter(adapter); shareList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub Intent shareIntent = new Intent(Intent.ACTION_SEND); AppInfo appInfo = (AppInfo) adapter.getItem(position); shareIntent.setComponent(new ComponentName(appInfo.getAppPkgName(), appInfo.getAppLauncherClassName())); shareIntent.setType("text/plain"); // shareIntent.setType("*/*"); //這里就是組織內(nèi)容了, 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); //設(shè)置允許在外點(diǎn)擊消失 sharePopupWindow.setOutsideTouchable(true); // 這個(gè)是為了點(diǎn)擊“返回Back”也能使其消失,并且并不會(huì)影響你的背景 sharePopupWindow.setBackgroundDrawable(new BitmapDrawable()); //xoff,yoff基于anchor的左下角進(jìn)行偏移。正數(shù)表示下方右邊,負(fù)數(shù)表示(上方左邊) //showAsDropDown(parent, xPos, yPos); sharePopupWindow.showAsDropDown(parent, -5, 5); }
注:ShareCustomAdapter自己建一個(gè)就行了。(顯示會(huì)有一個(gè)圖標(biāo)和一個(gè)分享的名字)
看完上述內(nèi)容,你們掌握分享應(yīng)用列表怎么在Android應(yīng)用中獲取的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!