How can I get a list of all installed apps?
Greetings! I want to receive the list of the established appendices in the Android. But the list is displayed only in LogCat. How to write, that it was displayed on phone? I use the given code: java:
package com.tipfile;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
public class dop extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>)
pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}}}
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textSelest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"/>
<ListView
android:id="@android:id/lis开发者_如何转开发t"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
The translator wrote through online. I do not know English language.
Use getInstalledPackages()
:
List pkgAppsList = context.getPackageManager().getInstalledPackages();
http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstalledPackages%28int%29
精彩评论