简单的Launcher
来源:互联网 发布:软件项目研发计划书 编辑:程序博客网 时间:2024/05/29 04:28
package com.qin.appinfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity implements OnItemClickListener {
private ListView listview = null;
private List<AppInfo> mlistAppInfo = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browse_app_list);
listview = (ListView) findViewById(R.id.listviewApp);
mlistAppInfo = new ArrayList<AppInfo>();
queryAppInfo(); // 查询所有应用程序信息
BrowseApplicationInfoAdapter browseAppAdapter = new BrowseApplicationInfoAdapter(
this, mlistAppInfo);
listview.setAdapter(browseAppAdapter);
listview.setOnItemClickListener(this);
}
// 点击跳转至该应用程序
public void onItemClick(AdapterView<?> arg0, View view, int position,
long arg3) {
// TODO Auto-generated method stub
Intent intent = mlistAppInfo.get(position).getIntent();
startActivity(intent);
}
// 获得所有启动Activity的信息,类似于Launch界面
public void queryAppInfo() {
PackageManager pm = this.getPackageManager(); // 获得PackageManager对象
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// 通过查询,获得所有ResolveInfo对象.
List<ResolveInfo> resolveInfos = pm
.queryIntentActivities(mainIntent, PackageManager.MATCH_DEFAULT_ONLY);
// 调用系统排序 , 根据name排序
// 该排序很重要,否则只能显示系统应用,而不能列出第三方应用程序
Collections.sort(resolveInfos,new ResolveInfo.DisplayNameComparator(pm));
if (mlistAppInfo != null) {
mlistAppInfo.clear();
for (ResolveInfo reInfo : resolveInfos) {
String activityName = reInfo.activityInfo.name; // 获得该应用程序的启动Activity的name
String pkgName = reInfo.activityInfo.packageName; // 获得应用程序的包名
String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label
Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标
// 为应用程序的启动Activity 准备Intent
Intent launchIntent = new Intent();
launchIntent.setComponent(new ComponentName(pkgName,
activityName));
// 创建一个AppInfo对象,并赋值
AppInfo appInfo = new AppInfo();
appInfo.setAppLabel(appLabel);
appInfo.setPkgName(pkgName);
appInfo.setAppIcon(icon);
appInfo.setIntent(launchIntent);
mlistAppInfo.add(appInfo); // 添加至列表中
}
}
}
}
- 简单的Launcher
- Launcher的简单介绍
- Launcher的简单实现,
- Launcher的简单讲解一
- Launcher的简单讲解二
- GridView实现简单的应用启动器Launcher
- Android实现简单Launcher的代码示例
- Android launcher应用的简单实现
- Android中的简单的launcher介绍
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- Android Launcher开发(四)Launcher概述及简单添加和删除应用程序的快捷方式
- Android创建简单的Launcher应用程序(一)
- Android创建简单的Launcher应用程序(二)
- android Launcher简单调整布局
- launcher修改--修改launcher的屏幕数
- Launcher简要分析:Launcher的功能实现
- Launcher简要分析:Launcher的其他内容
- 使元素hasLayout属性值为true的方法
- 深入理解js闭包
- android图标设计事宜
- UITextField介绍
- VA转换FileOffset
- 简单的Launcher
- synchronized同步机制
- boost log库
- 前几天写的来访用户端口号记录功能
- EJB实践和应用理解
- html 上传文件时 选中文件后自动开始上传
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- IO流分析整理
- 定位到驱动中的分派函数