android 获取程序,Android获取桌面应用程序

转载请注明出处,谢谢: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

看下图所示:3fca2d77c829f156b18a11ec6963f21b.png

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

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

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

@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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值