Last active
August 29, 2015 14:02
-
-
Save nishitpatel/3f4cc988a632777d555f to your computer and use it in GitHub Desktop.
Get Only Installed App List in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.vs2.applockfree.objects; | |
import java.util.ArrayList; | |
import java.util.List; | |
import android.content.ComponentName; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.pm.ApplicationInfo; | |
import android.content.pm.PackageInfo; | |
import android.content.pm.PackageManager; | |
import com.vs2.applockfree.appinfo.AppInfo; | |
import com.vs2.applockfree.appinfo.AppInfoResolver; | |
import com.vs2.applockfree.utilities.Logcat; | |
import com.vs2.applockfree.utilities.Utility; | |
public class ApplicationInformation { | |
private String applicationName; | |
private String packageName; | |
private String summary; | |
private String version; | |
private String className; | |
public ApplicationInformation(String applicationName, String packageName, | |
String summary, String ver, String classname) { | |
super(); | |
this.applicationName = applicationName; | |
this.packageName = packageName; | |
this.summary = summary; | |
this.version = ver; | |
this.className = classname; | |
} | |
public String getApplicationName() { | |
return applicationName; | |
} | |
public void setApplicationName(String applicationName) { | |
this.applicationName = applicationName; | |
} | |
public String getPackageName() { | |
return packageName; | |
} | |
public void setPackageName(String packageName) { | |
this.packageName = packageName; | |
} | |
public String getSummary() { | |
return summary; | |
} | |
public void setSummary(String summary) { | |
this.summary = summary; | |
} | |
public String getVersion() { | |
return version; | |
} | |
public void setVersion(String version) { | |
this.version = version; | |
} | |
public String getClassName() { | |
return className; | |
} | |
public void setClassName(String className) { | |
this.className = className; | |
} | |
//Get only installed app list | |
public static ArrayList<ApplicationInformation> getInstalledAppOnly( | |
Context context) { | |
try { | |
ArrayList<ApplicationInformation> applicationList = new ArrayList<ApplicationInformation>(); | |
PackageManager p = context.getPackageManager(); | |
final List<PackageInfo> appinstall = p | |
.getInstalledPackages(PackageManager.GET_PERMISSIONS | |
| PackageManager.GET_PROVIDERS); | |
if (appinstall != null && appinstall.size() > 0) { | |
for (int i = 0; i < appinstall.size(); i++) { | |
if (!isSystemPackage(appinstall.get(i))) { | |
String verisonName = appinstall.get(i).versionName; | |
String packagename = appinstall.get(i).packageName; | |
String applicationName = p.getApplicationLabel( | |
appinstall.get(i).applicationInfo).toString(); | |
String className = null; | |
Intent intent = p | |
.getLaunchIntentForPackage(packagename); | |
if (intent != null) { | |
ComponentName componentName = intent.getComponent(); | |
className = componentName.getClassName(); | |
} | |
p.getApplicationLabel(appinstall.get(i).applicationInfo) | |
.toString(); | |
ApplicationInformation application = new ApplicationInformation( | |
applicationName, packagename, packagename, | |
verisonName, className); | |
applicationList.add(application); | |
} | |
} | |
} | |
return applicationList; | |
} catch (Exception e) { | |
// TODO: handle exception | |
return null; | |
} | |
} | |
// Check if package is system app or not | |
public static boolean isSystemPackage(PackageInfo pkg) { | |
return ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true | |
: false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment