简体   繁体   English

需要帮助获取安装在Android手机上的所有应用程序的列表

[英]Need help getting a list of all apps installed on android phone

I am developing an application that needs a list of the apps that the user has installed on his phone. 我正在开发一个应用程序,需要用户在手机上安装的应用程序列表。 I have looked at ever tutorial online and none of them are specific enough, ie that show the code but never show where to put it 我曾经在网上看过教程,但没有一个是足够具体的,即显示代码但从未显示放在哪里

But being so new to programming I cannot use this because I do not know where to put it in my code, although I have found one code that works it does not show the version or the icon. 但是对编程这么新,我无法使用它,因为我不知道将它放在我的代码中的哪个位置,尽管我发现一个代码无法显示版本或图标。 I could really use someone to hold my hand on this one. 我真的可以用别人来抓住这个。

What I need specifically is an arraylist that shows the users installed apps, the icon, and the version. 我需要的是一个arraylist ,显示用户安装的应用程序,图标和版本。

Here is the code that I have working: 这是我工作的代码:

package com.fina; 包com.fina;

  import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.pm.PackageInfo; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class scan extends Activity { 

public ArrayList res = new ArrayList (); public ArrayList res = new ArrayList(); public ListView list; 公共ListView列表; public String app_labels[]; public String app_labels [];

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState); setContentView(R.layout.allc); 的setContentView(R.layout.allc);

  getPackages(); list = (ListView)findViewById(R.id.listView1); try{ list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, app_labels)); }catch(Exception e){ System.out.println("Err ++> " + e.getMessage()); Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } 

} private ArrayList getPackages() { ArrayList apps = getInstalledApps(false); private ArrayList getPackages(){ArrayList apps = getInstalledApps(false); final int max = apps.size(); final int max = apps.size(); for (int i=0; i < max; i++) { apps.get(i); for(int i = 0; i <max; i ++){apps.get(i); } return apps; } return apps; } }

private ArrayList getInstalledApps(boolean getSysPackages) { private ArrayList getInstalledApps(boolean getSysPackages){

  List <PackageInfo> packs = getPackageManager().getInstalledPackages(0); try{ app_labels = new String[packs.size()]; }catch(Exception e){ Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show(); } for(int i=0;i < packs.size();i++) { PackageInfo p = packs.get(i); if ((!getSysPackages) && (p.versionName == null)) { continue ; } PackageInfoStruct newInfo = new PackageInfoStruct(); newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString(); newInfo.pname = p.packageName; newInfo.versionName = p.versionName; newInfo.versionCode = p.versionCode; newInfo.icon = p.applicationInfo.loadIcon(getPackageManager()); res.add(newInfo); app_labels[i] = newInfo.appname; } return res; } } //This class is for storing the data for each application class PackageInfoStruct { String appname = ""; String pname = ""; String versionName = ""; int versionCode = 0; Drawable icon; } 

And here is my allc.xml that links to it: 这是我的allc.xml链接到它:

 <AbsoluteLayout android:id="@+id/absoluteLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/allcast" android:layout_width="61dp" android:layout_height="66dp" android:layout_x="0dp" android:layout_y="0dp" android:background="@drawable/invis" /> <Button android:id="@+id/downcast" android:layout_width="63dp" android:layout_height="60dp" android:layout_x="64dp" android:layout_y="3dp" android:background="@drawable/invis" /> <Button android:id="@+id/commcast" android:layout_width="51dp" android:layout_height="57dp" android:layout_x="255dp" android:layout_y="3dp" android:background="@drawable/invis" /> <Button android:id="@+id/achcast" android:layout_width="62dp" android:layout_height="58dp" android:layout_x="192dp" android:layout_y="2dp" android:background="@drawable/invis" /> <Button android:id="@+id/recocast" android:layout_width="59dp" android:layout_height="60dp" android:layout_x="128dp" android:layout_y="3dp" android:background="@drawable/invis" /> <ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_x="0dp" android:layout_y="71dp" > </ListView> </AbsoluteLayout> 

Please be as specific as possible with your answers, not just a link to a website with a code I could use, I really need someone to hold my hand on this one. 请尽可能详细地说明您的答案,而不仅仅是指向我可以使用的代码的网站的链接,我真的需要有人亲自抓住这个。

在我的教程,分步说明,并提供完整的源代码: https//xjaphx.wordpress.com/2011/06/12/create-application-launcher-as-a-list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM