如何显示用户将 Android 应用程序安装到列表视图? [关闭]
Posted
技术标签:
【中文标题】如何显示用户将 Android 应用程序安装到列表视图? [关闭]【英文标题】:How to show Android applications are installed by user to a listview? [closed] 【发布时间】:2012-12-30 20:17:13 【问题描述】:我正在编写一个类似任务管理器的应用程序。我想知道如何将用户安装的android应用程序显示到列表视图中,请大家帮助我
我刚刚做了一些这样的功能来管理Android中的应用程序,代码还可以,但我想添加更多功能
public void onClick(View v)
// TODO Auto-generated method stub
switch (v.getId())
case R.id.appinfo:
final ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(int i = 0; i < procInfos.size(); i++)
tv.setText(tv.getText().toString()+procInfos.get(i).processName+
" " + String.valueOf(procInfos.get(i).processName.length())+"\n");
if(procInfos.get(i).processName.equals("com.android.camera"))
Toast.makeText(getApplicationContext(), "Camera App is running", Toast.LENGTH_LONG).show();
else
Toast.makeText(getApplicationContext(), "Camera App is not running", Toast.LENGTH_LONG).show();
break;
case R.id.taskinfo:
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < recentTasks.size(); i++)
tv.setText("Executed app"+ "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");
break;
case R.id.serviceinfo:
final String APP_TAG = "tag";
ActivityManager activityManager1 = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo>runningServices = activityManager1.getRunningServices(50);
for (int i = 0;i < runningServices.size();i++)
ActivityManager.RunningServiceInfo runningServiceInfo = runningServices.get(i);
tv.setText(APP_TAG + "Process " + runningServiceInfo.process + " with component " + runningServiceInfo.service.getClassName());
【问题讨论】:
我们会帮助你,但你做了什么?或者您想要我们这边的完整代码? :) 我做了一个这样的程序 【参考方案1】:你可以使用 packageManager 来做到这一点,
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages)
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG,
"Launch Activity :"
+ pm.getLaunchIntentForPackage(packageInfo.packageName));
// put application name to an Array, then set listviews adapter with this array
【讨论】:
以上是关于如何显示用户将 Android 应用程序安装到列表视图? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
[Android][App不显示在最近使用过的应用程序列表中]
如何创建与每个已安装的 android 应用程序(在用户手机上)关联的活动(android 类)的列表(文件名、位置)?