如何获得在Android的所有homescreens? [英] How to get all homescreens in Android?

查看:177
本文介绍了如何获得在Android的所有homescreens?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新android开发。我知道,每一个主屏幕是启动一个工作区。我想获得的所有屏幕上的应用程序图标的所有位置信息,那么,有没有办法让这些画面对象的列表及其图标的信息?

I am new to android development. I know that every homescreen is a Workspace in Launcher. I want to get all the position info of all application icons on the screen, so is there any way to get a list of these screen objects and their icon info?

地址:我希望有更多的应用程序图标和屏幕之间的关系。例如,我要一个特定的应用程序图标的位置信息,包括它出现在(即屏幕列表的指数)的屏幕。

ADD: What I expect more is the relationships between app icon and screen. For example, I want the position info of a certain app icon, including which screen it appears on(that is the index of the screen list).

推荐答案

首先创建一个bean来存储这样的应用程序信息

first create a bean to store app info like this

public class Bean {

 String appName;
 String packName;
 Drawable icon;
 Date installTime;
 Date updateTime;
 int size;
}

现在创建四个名单在这里ApplicationInfo,结果,PACKNAME,豆。

now create four list here for ApplicationInfo,results,packname,bean.

public class AllApplications extends Activity  {

List<ApplicationInfo> AppList;
private ArrayList<String>results;
private ArrayList<String>packName;
public ArrayList<Bean> list;
ProgressDialog progress;
ActivityManager am ;
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_all_applications);


    try 
    {
        new LoadApps().execute();
    } 
    catch (Exception e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Log.e("Exception",e.toString());
    }

}


class LoadApps extends AsyncTask<Void, Void,String>
{

    @Override 
    protected void onPreExecute() { 
        progress= ProgressDialog.show(AllApplications.this,"Loading",
                "Please Wait");
    } 
    @Override
    protected String doInBackground(Void... params) 
    {
        PackageManager pm = AllApplications.this.getPackageManager();
        list = new ArrayList<Bean>();
        AppList = new ArrayList<ApplicationInfo>();
        AppList = pm.getInstalledApplications(0);
        Log.e("Package info",""+AppList);
        results = new ArrayList<String>();
        packName = new ArrayList<String>();
        Log.e("Total package list",""+AppList.size());

        for(int i=0;i<AppList.size();i++)
        {
            Bean bean = new Bean();
            ApplicationInfo appInfo  = AppList.get(i); 
            try 
            {
                PackageInfo packInfo = pm.getPackageInfo(appInfo.packageName,0);
                try 
                {
                    java.lang.reflect.Field field1 = PackageInfo.class.getField("firstInstallTime");
                    long firstIns = field1.getLong(packInfo);
                    Date insDate = new Date(firstIns);
                    bean.installTime = insDate;
                    java.lang.reflect.Field field2 = PackageInfo.class.getField("lastUpdateTime");
                    long lastUpdate = field2.getLong(packInfo);
                    Date upDate = new Date(lastUpdate);
                    bean.updateTime = upDate;

                } 
                catch (NoSuchFieldException e) 
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            } 
            catch (NameNotFoundException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Log.e("ins package", "" + appInfo.packageName);
            Log.e("ins package name", "" +appInfo.loadLabel(pm));
            Log.e("launched activity :", "" + pm.getLaunchIntentForPackage(appInfo.packageName)); 
            bean.appName = (String) appInfo.loadLabel(pm);
            bean.packName = appInfo.packageName;
            bean.icon = appInfo.loadIcon(getPackageManager());
            list.add(bean);
            //              PackageInfo. this.firstInstallTime(a);
        }

        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        progress.dismiss();

    }

}}

试试这个它会帮助你很多,让我知道更多的帮助。

Try this it ll help you alot,and let me know for more help.

这篇关于如何获得在Android的所有homescreens?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆