繁体   English   中英

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

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

我正在开发一个应用程序,需要用户在手机上安装的应用程序列表。 我曾经在网上看过教程,但没有一个是足够具体的,即显示代码但从未显示放在哪里

但是对编程这么新,我无法使用它,因为我不知道将它放在我的代码中的哪个位置,尽管我发现一个代码无法显示版本或图标。 我真的可以用别人来抓住这个。

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

这是我工作的代码:

包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(); 公共ListView列表; public String app_labels [];

public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState); 的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); final int max = apps.size(); for(int i = 0; i <max; i ++){apps.get(i); } return apps; }

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; } 

这是我的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> 

请尽可能详细地说明您的答案,而不仅仅是指向我可以使用的代码的网站的链接,我真的需要有人亲自抓住这个。

在我的教程,分步说明,并提供完整的源代码: 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