android獲得所有的安裝app列表,並運行指定app,androidapp

來源:互聯網
上載者:User

android獲得所有的安裝app列表,並運行指定app,androidapp

如何獲得andorid手機的程式安裝列表,並調用其中一個app運行?
我目前試過如下方式

Intent intent = new Intent(ACTION_MAIN);
intent.addCategory(CATEGORY_LAUNCHER);

這裡只是展示ACTION_MAIN 類型的應用程式,我知道PackageManager 可以獲得程式的安裝列表。但是如何調用其中一個程式運行呢?

處理方法

按照下面的代碼運行,就會獲得已經安裝的程式列表

123 finalIntent mainIntent = newIntent(Intent.ACTION_MAIN, null);mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);finalList pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent,0);

或者下面連結和代碼也

Link: http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon
Here a good example:

123456789101112131415161718 classPInfo {    privateString appname = "";    privateString pname = "";    privateString versionName = "";    privateint versionCode = 0;    privateDrawable icon;    privatevoid prettyPrint() {        Log.v(appname + "\t"+ pname + "\t"+ versionName + "\t"+ versionCode);    }} privateArrayList<pinfo> getPackages() {    ArrayList<pinfo> apps = getInstalledApps(false);/* false = no system packages */    finalint max = apps.size();    for(inti=0; i<max; arraylist<pinfo=""private=""}=""apps;=""return=""apps.get(i).prettyprint();=""{=""i++)=""> getInstalledApps(booleangetSysPackages) {    ArrayList<pinfo> res = newArrayList<pinfo>();    List<packageinfo> packs = getPackageManager().getInstalledPackages(0);    for(inti=0;i<packs.size();i++) }=""return=""{=""pre=""<=""res;=""res.add(newinfo);=""newinfo.icon="p.applicationInfo.loadIcon(getPackageManager());"newinfo.versioncode="p.versionCode;"newinfo.versionname="p.versionName;"newinfo.pname="p.packageName;"newinfo.appname="p.applicationInfo.loadLabel(getPackageManager()).toString();"pinfo();=""newinfo="new"pinfo="";=""continue=""null))=""(p.versionname="="&&=""((!getsyspackages)=""if=""p="packs.get(i);"packageinfo=""></packs.size();i++)></packageinfo></pinfo></pinfo></max;></pinfo></pinfo>


原文地址:http://www.itmmd.com/201411/122.html 
該文章由 萌萌的IT人 整理髮布,轉載須標明出處。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.