这个比较简陋,只是自己随便练手瞎写的,以后会继续完善
1.将自己的程序加入到系统launcher选项中
在manifest文件中自己的主程序中的intentFilter中加入如下两行代码即可
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
2.用GridView显示所有安装的程序,并添加点击事件
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<GridView android:layout_width="fill_parent"
android:id="@+id/apps"
android:numColumns="4"
android:layout_height="wrap_content">
</GridView>
</LinearLayout>
java程序
package com.test.lancher;
import java.util.List;
import android.app.Activity;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class LancherActivity extends Activity {
GridView mGrid;
private List<ResolveInfo> mApps;
private OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
//程序信息
ResolveInfo info = mApps.get(arg2);
//包名
String pkg = info.activityInfo.packageName;
// 主activity类名
String cls = info.activityInfo.name;
ComponentName componet = new ComponentName(pkg, cls);
Intent i = new Intent();
i.setComponent(componet);
startActivity(i);
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadApps();
setContentView(R.layout.main);
mGrid = (GridView) findViewById(R.id.apps);
mGrid.setAdapter(new AppsAdapter());
mGrid.setOnItemClickListener(listener);
}
//获取所有程序的信息
private void loadApps() {
Intent mIntent = new Intent(Intent.ACTION_MAIN, null);
mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mApps = getPackageManager().queryIntentActivities(mIntent, 0);
}
public class AppsAdapter extends BaseAdapter {
public AppsAdapter() {
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i;
if (convertView == null) {
i = new ImageView(LancherActivity.this);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new GridView.LayoutParams(50, 50));
} else {
i = (ImageView) convertView;
}
ResolveInfo info = mApps.get(position);
i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));
return i;
}
public final int getCount() {
return mApps.size();
}
public final Object getItem(int position) {
return mApps.get(position);
}
public final long getItemId(int position) {
return position;
}
}
}
分享到:
相关推荐
Arctium WoW Client Launcher 27377版本。 HOWTO: 安装方法: 1.Use 7zip/WinRAR to extract the archive into your wow folder. 1.用解压软件将压缩包内容解压到WOW文件夹内,即将Arctium WoW Client Launcher....
7.1 8.1 9.0 10.0 两个launcher之间切换,设置默认launcher
meizu 的launcher2 美化修改过的
android5.1原生launcher
此资源是在安卓巴士交会上王鹏工程师分享的Launcher3的原理及二次开发pdf。文中介绍啦Launcher3的框架和主要流程,能给从事Lauuncher3开发和桌面定制的开发人员启迪。特此分享出来。
Launcher3 更改官方的Launcher3使得可以在Android Studio编译 原始地址,从5892520提交开始 最小sdk版本为16 Android 5.0 版本及以上可能会出现因为相同权限声明而不能安装的问题 如果你想要可以在Eclipse编译的...
一个可以切换主界面launcher,设置默认launcher的示例
Androidlauncher开发.pdf
Android系统桌面Launcher3源码,可直接在Android Studio中编译。
launcher3动画效果源码,只供学习使用。
介绍launcher框架
Warcraft III Launcher.exe
Android11 Launcher3
rxjh(yulgang) launcher code
android2.3 launcher分析
Android launcher 源码调试
5.0 Launcher3的源码
MUEMU LAUNCHER TOP FUNCIONANDO
javalauncher
Tekkit Launcher