Android获取桌面应用程序

来源:互联网 发布:淘宝靠谱的日本代购店 编辑:程序博客网 时间:2024/05/22 12:35

转载请注明出处,谢谢:http://blog.csdn.net/harryweasley/article/details/50057029

首先在看这个博客之前, 你可以先看下这个博客,http://blog.csdn.net/harryweasley/article/details/50057707

里面介绍了两种方式来获取应用程序的信息,一种是packageInfo,一种是ResolveInfo,通过packageInfo来获取应用信息,会出现一个bug,那就是如果该应用,有多个图标和名字,那么只会默认显示第一个。所以我现在用ResolveInfo来获取用户信息。

关于多个图标和名字,不理解的,可以看这篇文章。http://blog.csdn.net/harryweasley/article/details/48051565
看下图所示:这里写图片描述

一共有四个相同包名,但是图标和名字都不同的同一个应用。

其实获得桌面上的所有应用程序信息,还是比较简单的,以下就是主要代码了,文章最后,会贴出资源。

package com.example.getlauncherapp;import java.util.List;import android.app.Activity;import android.content.Intent;import android.content.pm.PackageManager;import android.content.pm.ResolveInfo;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.ListView;public class MainActivity extends Activity {    private ListView myListView;    private List<ResolveInfo> resolveInfoList;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        myListView = (ListView) findViewById(R.id.listView);        getLauncherApp();        MyBaseAdapter adapter = new MyBaseAdapter(this, resolveInfoList);        myListView.setAdapter(adapter);    }    /**     * 获取到桌面的应用程序     */    private void getLauncherApp() {        // 桌面应用的启动在INTENT中需要包含ACTION_MAIN 和CATEGORY_HOME.        Intent intent = new Intent();        intent.addCategory(Intent.CATEGORY_LAUNCHER);        intent.setAction(Intent.ACTION_MAIN);        PackageManager manager = getPackageManager();        resolveInfoList = manager.queryIntentActivities(intent, 0);    }}

本项目的下载链接为:http://download.csdn.net/detail/harryweasley/9302849
结束。

0 0
原创粉丝点击