Hi,
   I am trying to find the *package name *of an application based on 
'Application Name' by scanning through all installed applications on the 
device. Using the below code, it works, but takes about 15~20 secs to find 
the package name on a device loaded with applications.

public String findApplicationPackage( String sAppName ){

   String                     sPackageName        = null;

   PackageManager           pm                  = m_Context.getPackageManager();

 //get a list of installed apps.
  List<ApplicationInfo>     packages            = 
pm.getInstalledApplications(PackageManager.GET_META_DATA);

  ApplicationInfo   ap  = new ApplicationInfo();
  ap.loadLabel(pm);



   for (ApplicationInfo packageInfo : packages) {

        String          sApp                = packageInfo.loadLabel( pm 
).toString();

        //Log.d(TAG, "Installed AppName = " + appName + "  ,package :" + 
packageInfo.packageName );
        //Log.d(TAG,   "Launch Activity :" + 
pm.getLaunchIntentForPackage(packageInfo.packageName)); 

        if( sApp.compareTo( sAppName ) == 0 ){

            sPackageName    = packageInfo.packageName;
            break;
        }

   }// the getLaunchIntentForPackage  

   return sPackageName;
}

 How do I optimize this and reduce the time?

Thanks,
DK


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to