Java 如何获取android设备上所有已安装应用程序的列表

Java 如何获取android设备上所有已安装应用程序的列表,java,android,Java,Android,您好,我正在开发一个与MIUI Home具有类似UI的应用程序,但是我不知道如何让该应用程序显示设备上所有已安装的应用程序 这是我的密码: package com.d4a.tobias; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import a

您好,我正在开发一个与MIUI Home具有类似UI的应用程序,但是我不知道如何让该应用程序显示设备上所有已安装的应用程序

这是我的密码:

package com.d4a.tobias;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SpringboardActivity extends Activity {

    public static final String LOGTAG = "Springboard";
    private final String TAG = "SpringboardActivity";

    private RelativeLayout mRlRoot;
    /*private RelativeLayout mRlFullGrid;
    private RelativeLayout mRlTabBar;
    private DragView mDragView;
    private DragViewTabBar mDragViewTabBar;*/
    private DraggableView mDragView;
    private LayoutInflater mInflater;

//  private ArrayList<View> mGridItems;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.springboard);

        Log.i(LOGTAG, TAG + " - onCreate");

        mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mRlRoot = (RelativeLayout) findViewById(R.id.sb_RlRoot);
//        mDragView = new DragView(this);
        mDragView = new DraggableView(this);
//        mDragViewTabBar = new DragViewTabBar(this);
        mRlRoot.addView(mDragView);
//        mRlRoot.addView(mDragViewTabBar);
    }





    @Override
    protected void onStart() {
        super.onStart();
        Log.i(LOGTAG, TAG + " - onStart");

        addItemsToGridView();
//      addItemsToTabBar();
    }

    private void addItemsToGridView() {
        mDragView.setGridViewCount(10);
        for (int i = 0; i < 14; i++) {
            View view = mInflater.inflate(R.layout.one_item, null);
            ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
            TextView tvIcon = (TextView) view.findViewById(R.id.tvIcon);
            tvIcon.setText("EG "+i);
            int childSize = mDragView.getChildSize();
            ivIcon.setBackgroundResource(R.drawable.chrome_icon);
            LinearLayout.LayoutParams ivParams = (LinearLayout.LayoutParams) ivIcon.getLayoutParams();
            ivParams.width = childSize / 2;
            ivParams.height = childSize / 2;
            ivIcon.setLayoutParams(ivParams);
            mDragView.addViewToLayout(view, i, new LayoutParams(childSize, childSize));
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.springboard, menu);
        return true;
    }
}
package com.d4a.tobias;
导入java.util.ArrayList;
导入android.app.Activity;
导入android.content.Context;
导入android.content.Intent;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.Menu;
导入android.view.view;
导入android.view.ViewGroup.LayoutParams;
导入android.widget.ImageView;
导入android.widget.LinearLayout;
导入android.widget.RelativeLayout;
导入android.widget.TextView;
公开课跳板活动扩展活动{
公共静态最终字符串LOGTAG=“Springboard”;
私有最终字符串标记=“SpringboardActivity”;
私人相对论;
/*私有相对论的mRlFullGrid;
私人相对人Yout mRlTabBar;
私人DragView mDragView;
私人Dragviewtabar mDragViewTabBar*/
私有DraggableView-mDragView;
私人停车场;
//私人阵列列表管理项;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.springboard);
Log.i(LOGTAG,TAG+“-onCreate”);
mInflater=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
mRlRoot=(RelativeLayout)findViewById(R.id.sbrlroot);
//mDragView=新的DragView(此);
mDragView=新的DragTableView(此);
//mDragViewTabBar=新的DragViewTabBar(此);
mRlRoot.addView(mDragView);
//mRlRoot.addView(mDragViewTabBar);
}
@凌驾
受保护的void onStart(){
super.onStart();
Log.i(LOGTAG,TAG+“-onStart”);
addItemsToGridView();
//addItemsToTabBar();
}
私有void addItemsToGridView(){
mDragView.setGridViewCount(10);
对于(int i=0;i<14;i++){
View View=mInflater.充气(R.LAYOU.one_项,空);
ImageView ivIcon=(ImageView)view.findViewById(R.id.ivIcon);
TextView tvIcon=(TextView)view.findViewById(R.id.tvIcon);
tvIcon.setText(“EG”+i);
int childSize=mDragView.getChildSize();
ivIcon.setBackgroundResource(R.drawable.chrome_图标);
LinearLayout.LayoutParams ivParams=(LinearLayout.LayoutParams)ivIcon.getLayoutParams();
ivParams.width=儿童尺寸/2;
ivParams.height=儿童尺寸/2;
ivIcon.setLayoutParams(ivParams);
mDragView.addViewToLayout(视图,i,新布局参数(childSize,childSize));
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(右菜单、跳板、菜单);
返回true;
}
}
我已经试过了,但是运气不好 我真的很紧张

任何帮助都将是惊人的


提前谢谢

获取所有已安装应用程序的列表

  final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

我应该把它放在我的代码中的什么地方?很抱歉听起来像个傻瓜,非常感谢您的快速回复!!!那由你决定。该列表存储在pkgAppsList中,因此我想在使用列表值之前,可以在任何地方找到它。你确定你用谷歌搜索了它吗?首次命中(偶数堆栈溢出):