0

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).

vulgur
  • 51
  • 1
  • 9
  • 1
    yes we can get all the installed apps name n their respective icon launcher and some other info like installed time,update time etc.If you want codes plz let me know.. – Rohit Goswami May 15 '14 at 04:34
  • yes, I would appreciate it if you show me the example code. – vulgur May 15 '14 at 05:05
  • Yes we can get list of apps installed in our device please refer this link http://stackoverflow.com/questions/6165023/get-list-of-installed-android-applications – Meenal May 15 '14 at 05:05
  • 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). – vulgur May 15 '14 at 05:39

1 Answers1

1

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;
}

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.

Howli
  • 12,291
  • 19
  • 47
  • 72
Rohit Goswami
  • 617
  • 5
  • 17