超级简单的launcher,显示安装的所有apk
1.manifest.xml属性:
<category android:name = "android.intent,category.HOME"/>
<category android:name = "android.intent.category.DEFAULT"/>
2.
获取系统apk列表:
private void loadApps() {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mApps = getPackageManager().queryIntentActivities(mainIntent, 0);
}
adapter代码:
package com.xt.launcher;
import java.util.List;
import android.content.Context;
import android.content.pm.ResolveInfo;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
public class AppsAdapter extends BaseAdapter{
Context context;
List mmApps;
public AppsAdapter(Context paramContext, List paramList) {
this.context = paramContext;
this.mmApps = paramList;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder ;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(this.context).inflate(R.layout.grid_item, parent,false);
viewHolder.iv = ((ImageView)convertView.findViewById(R.id.image_item));
viewHolder.tv = ((TextView)convertView.findViewById(R.id.text_item));
convertView.setTag(viewHolder);
} else{
viewHolder = (ViewHolder)convertView.getTag();
}
ResolveInfo localResolveInfo = (ResolveInfo)this.mmApps.get(position);
viewHolder.iv.setImageDrawable(localResolveInfo.activityInfo.loadIcon(this.context.getPackageManager()));
viewHolder.tv.setText(localResolveInfo.loadLabel(this.context.getPackageManager()));
return convertView;
}
class ViewHolder
{
ImageView iv;
TextView tv;
ViewHolder() {}
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.mmApps.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return this.mmApps.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}