我使用以下代码来区分用户安装的应用程序和系统应用程序:
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages)
{
if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
Log.d(TAG, "Installed package (System) :" + packageInfo.packageName);
else
Log.d(TAG, "Installed package (User) :" + packageInfo.packageName);
}
这如何使某些应用程序成为用户安装的应用程序,而实际上并非如此。以下是我的模拟器中的 LogCat:
Installed package (User) :com.android.smoketest
Installed package (User) :com.android.widgetpreview
Installed package (User) :com.example.android.livecubes
Installed package (User) :com.example.android.apis
Installed package (User) :com.android.gesture.builder
Installed package (User) :com.example.android.softkeyboard
Installed package (User) :com.android.smoketest.tests
Installed package (User) :faheem.start
理想情况下,用户安装的应用程序中应该只输出最后一个应用程序。