I want to get icons of my all installed apps. Can I get that icons using package manager? Is there any function for it? Or any other way to get icons of all installed apps in bitmap?
Thanks!
try {
String pkg = "com.app.my";//your package name
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
imageView.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException ne) {
}
Check here for more details.
Above answers are pretty good.
Your Question is:- Get icons of all installed apps in android?
you want list of install apps icon
Here is the code which help you to get install apps list with Application (icons,packages names).
**Declare variable in your Activity**
private CustomAppListAdapter customAppListAdapter;
private ArrayList<AppListMain> appListMainArrayList;
private AppListMain appListMain;
Just call below function loadApps() in your Activity onCreate()
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_list);
loadApps();
}
public void loadApps() {
try {
packageManager = getPackageManager();
appListMainArrayList = new ArrayList<>();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : resolveInfoList) {
AppListMain appListMain = new AppListMain();
appListMain.setAppIcon(resolveInfo.activityInfo.loadIcon(packageManager));
appListMain.setAppName(resolveInfo.loadLabel(packageManager).toString());
appListMain.setAppPackage(resolveInfo.activityInfo.packageName);
appListMainArrayList.add(appListMain);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Here is Link for reference
OR
You can download custom launcher code from My Github repository
I find it the easiest way:
private List<ResolveInfo> installedApps() {
final Intent main_intent = new Intent(Intent.ACTION_MAIN, null);
main_intent.addCategory(Intent.CATEGORY_LAUNCHER);
return package_manager.queryIntentActivities(main_intent, 0);
}
Now to get the icons, use this:
for(ResolveInfo ri : installedApps()) {
// to get drawable icon --> ri.loadIcon(package_manager)
}
Try this way: Make a class called PackageInformation:
public class PackageInformation {
private Context mContext;
public PackageInformation(Context context) {
mContext = context;
}
class InfoObject {
public String appname = "";
public String pname = "";
public String versionName = "";
public int versionCode = 0;
public Drawable icon;
public void InfoObjectAggregatePrint() { //not used yet
Log.v(appname, appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList < InfoObject > getPackages() {
ArrayList < InfoObject > apps = getInstalledApps(false);
final int max = apps.size();
for (int i = 0; i < max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
public ArrayList < InfoObject > getInstalledApps(boolean getSysPackages) {
ArrayList < InfoObject > res = new ArrayList < InfoObject > ();
List < PackageInfo > packs = mContext.getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue;
}
InfoObject newInfo = new InfoObject();
newInfo.appname = p.applicationInfo.loadLabel(mContext.getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(mContext.getPackageManager());
res.add(newInfo);
}
return res;
}
}
tuck this away somewhere and now to access the info from your working Activity class do this:
PackageInformation androidPackagesInfo = new PackageInformation(this);
ArrayList < InfoObject > appsData = androidPackagesInfo.getInstalledApps(true);
for (InfoObject info: appsData) {
Toast.makeText(MainActivity.this, info.appname, 2).show();
Drawable somedrawable = info.icon;
}
Here below is the code with which you can get the icons of all installed Apps.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
// try getting the properly colored launcher icons
LauncherApps launcher = (LauncherApps) this.getSystemService(LAUNCHER_APPS_SERVICE);
List<LauncherActivityInfo> activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle());
drawable = activityList.get(0).getBadgedIcon(0);
} catch (Exception e) {
}
}
if (drawable == null) {
try {
getPackageManager().getApplicationIcon(packageName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
Related
In android,how can I get a list of the app names(not package names) of all my installed non-system apps along with their app icons
This method helps you to get all installed apps detail from your device like name, package name, icon, version etc..
private ArrayList<PackageAppInfo> getInstalledApps() {
ArrayList<PackageAppInfo> res = new ArrayList<>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if ((p.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
if (p.packageName.equals(MyOwnApplication.getInstance().getPackageName())) {
continue;
}
PackageAppInfo newInfo = new PackageAppInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
ApplicationInfo applicationInfo;
long size;
try {
applicationInfo = getPackageManager().getApplicationInfo(p.packageName, PackageManager.GET_META_DATA);
File file = new File(applicationInfo.publicSourceDir);
size = file.length();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
size = 0;
}
newInfo.size = size;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
} else {
String appName = p.applicationInfo.loadLabel(getPackageManager()).toString();
}
}
return res;
}
PackageAppInfo.java
public class PackageAppInfo {
public String appname = "";
public String pname = "";
public String versionName = "";
public int versionCode = 0;
public int permissions = 0;
public Drawable icon;
public long size;
}}
I Already know how to get the package names of applications installed by the user.
But i cannot figure out how to get the package names of applications that are preinstalled or are system-ware like (Samsung Fit, Calender etc.) ??
List<ApplicationInfo> packages = context.getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Package :" + packageInfo.packageName);
Log.d(TAG, "Launcher Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
}
ApplicationInfo is having a packageName field which provides you package name of the application.
You can use below code to get the list of system application PackageInfo,
public static ArrayList<PackageInfo> getSystemPackageInfos(final Activity context) {
ArrayList<PackageInfo> list = new ArrayList<PackageInfo>();
ArrayList<String> packageNames = new ArrayList<String>();
PackageManager pm = context.getPackageManager();
List<PackageInfo> pinfoList = pm.getInstalledPackages(0);
Collections.sort(pinfoList, PackageNameComparator);
for (PackageInfo pinfo : pinfoList) {
packageNames.add(pinfo.packageName);
boolean isSystem = false;
if (((pinfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)) {
isSystem = false;
} else {
isSystem = true;
}
if (pinfo.applicationInfo.sourceDir.startsWith("/data/app/") && isSystem) {
//Non-system app
isSystem = false;
}
if (!isSystem) {
continue;
}
Bitmap icon = null;
Drawable apkIcon = getApplicationIcon(pinfo.applicationInfo, context);
try {
icon = Bitmap.createBitmap(apkIcon.getIntrinsicWidth(), apkIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(icon);
apkIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
apkIcon.draw(canvas);
} catch (ClassCastException e) {
}
String name = pinfo.applicationInfo.loadLabel(pm).toString();
long apkSize = new File(pinfo.applicationInfo.sourceDir).length();
list.add(pinfo);
}
return list;
}
I want to add an option in my file manager to show the App Icons of a directory. The code below didn't work; what did I do wrong?
ImageView icon;
private static Activity activity;
String temp = mFileMang.getCurrentDir();
} else if (sub_ext.equalsIgnoreCase("apk")) {
final Drawable appicon;
try {
PackageInfo packageInfo = activity.getPackageManager()
.getPackageArchiveInfo(temp,
PackageManager.GET_ACTIVITIES);
ApplicationInfo appInfo = packageInfo.applicationInfo;
appInfo.sourceDir = temp;
appInfo.publicSourceDir = temp;
appicon = appInfo
.loadIcon(activity.getPackageManager());
mViewHolder.icon.setImageDrawable(appicon);
} catch (Exception e) {
mViewHolder.icon.setImageResource(R.drawable.appicon);
}
try this.. i fetch the icon from the sd card directory ..icon from the apk files which are not installed ...
public class A extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_listing);
ListView list = (ListView) findViewById(R.id.app_listing);
ArrayList<PackageInfoStruct> listData = getApks();
list.setAdapter(new TestAdapter(listData, A.this));
}
class PackageInfoStruct {
String appname = "";
String pname = "";
String versionName = "";
int versionCode = 0;
Drawable icon;
String datadir = "";
}
public ArrayList<PackageInfoStruct> res;
private ArrayList<PackageInfoStruct> getApks() {
try {
String path = Environment.getExternalStorageDirectory() + "/test";
File file = new File(path);
String[] list = file.list();
res = new ArrayList<PackageInfoStruct>();
for (String str : list) {
String not_installed_apk_file = path + "/" + str;
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(
not_installed_apk_file, 0);
if (pi == null)
continue;
// the secret are these two lines....
pi.applicationInfo.sourceDir = not_installed_apk_file;
pi.applicationInfo.publicSourceDir = not_installed_apk_file;
//
Drawable APKicon = pi.applicationInfo.loadIcon(pm);
String AppName = (String) pi.applicationInfo.loadLabel(pm);
PackageInfoStruct pack = new PackageInfoStruct();
pack.icon = APKicon;
pack.pname = AppName;
res.add(pack);
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
private ArrayList<PackageInfoStruct> getInstalledApps() {
try {
res = new ArrayList<PackageInfoStruct>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(
0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
PackageInfoStruct newInfo = new PackageInfoStruct();
newInfo.appname = p.applicationInfo.loadLabel(
getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.datadir = p.applicationInfo.dataDir;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(this
.getPackageManager());
res.add(newInfo);
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
}
PackageManager..getPackageArchiveInfo(..) method will work only for installed apks, means it will operate only on an apk file, which has already been installed. Currently you maybe checking this on an apk file, which might not be installed and thus getting package info is failed.
What you can do is:
Unzip the apk file programatically (Basically apk file is a zip file, and you can extract it programatically. see http://www.jondev.net/articles/Unzipping_Files_with_Android_(Programmatically) )
Get the AndroidManifest.xml file from the zip entry
Parse the AndroidManifest.xml file ( see How to parse the AndroidManifest.xml file inside an .apk package )
Get the xml attribute 'android:icon' from it
Read the icon file from the zip entry again as bitmap.
use this icon bitmap wherever you want.
Just Try with this-
ImageView icon;
private static Activity activity;
String temp = mFileMang.getCurrentDir();
} else if (sub_ext.equalsIgnoreCase("apk")) {
final Drawable appicon;
try {
PackageInfo packageInfo = activity.getPackageManager()
.getPackageArchiveInfo(temp,
PackageManager.GET_ACTIVITIES);
ApplicationInfo appInfo = packageInfo.applicationInfo;
appInfo.sourceDir = temp;
appInfo.publicSourceDir = temp;
PackageManager pm = getPackageManager();
appicon = pm.getApplicationIcon(appInfo.packageName);
mViewHolder.icon.setImageDrawable(appicon);
} catch (Exception e) {
mViewHolder.icon.setImageResource(R.drawable.appicon);
}
to add this http://stackoverflow.com/questions/17919151/android-app-icon-filemanager/17924795#17924795 to my code i need to cut it. finally i got this:
but when I open the directory it load only 1 icon and show it for all other apps too.
https://www.dropbox.com/s/e2bonh3fkfseggf/Screenshot_2013-07-31-13-58-18.png
File file = new File(temp + "/" + mDataSource.get(position));
} else if (sub_ext.equalsIgnoreCase("apk")) {
try {
Drawable icon = getApk(file);
mViewHolder.icon.setImageDrawable(icon);
} catch (Exception e) {
mViewHolder.icon.setImageResource(R.drawable.appicon);
}
private Drawable getApk(File file2) {
try {
String path = mFileMang.getCurrentDir();
File file = new File(path);
String[] list = file.list();
for (String str : list) {
String not_installed_apk_file = path + "/" + str;
PackageManager pm = mContext.getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(
not_installed_apk_file, 0);
if (pi == null)
continue;
// the secret are these two lines....
pi.applicationInfo.sourceDir = not_installed_apk_file;
pi.applicationInfo.publicSourceDir = not_installed_apk_file;
//
res = pi.applicationInfo.loadIcon(pm);
}
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
PackageManager pm = context.getPackageManager();
PackageInfo info =pm.getPackageArchiveInfo(apkPath,PackageManager.GET_ACTIVITIES);
i want the application list that is installed from google play or from any external storage, but not the pre installed system application.
i just use below code.....
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v("", "*** appname = " + appname + " *** \n" + " packagename = " + pname + "\n" + " version name = " + versionName + "\n" + " version code = " + versionCode + " \n\n\n\n");
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(true); /* false = no system packages */
final int max = apps.size();
int i = 0;
for (i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
Log.v(TAG, "Total APPs = "+i);
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(PackageManager.GET_META_DATA);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PInfo newInfo = new PInfo();
newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
res.add(newInfo);
}
return res;
}
but this code gives me information of system application also.....
can anybody know how to get only installed application except the installed system application ?
thanks....
To discover if your application is a system application you can use the following code:
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);
for (ApplicationInfo aInfo: installedApps) {
if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
// system application
} else {
//user application
}
}
If you need to discover if an application is installed from a market you need to use the following method of Package: getInstallerPackageName. It will return the packageName of the application that installed your application.
public class AppList extends Activity {
private ListView lView;
private ArrayList results = new ArrayList();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lView = (ListView) findViewById(R.id.list1);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
results.add(rInfo.activityInfo.applicationInfo
.loadLabel(pm).toString());
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
.loadLabel(pm).toString());
}
lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
}
}
I have a list activity which display all running applications in the device. it's displaying a default icon for all application . but I need to get actual application Icon for each application in the list.
public class ApplicationList extends ListActivity {
DataHelper dh;
ImageView vi;
private Drawable icon;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.applist);
dh = new DataHelper(getApplicationContext());
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
Log.d("Test1", "INSERTING APP LIST TO SERVER DB");
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
ArrayList<String> applist = new ArrayList<String>();
for(ResolveInfo rInfo: list){
applist.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString() );
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.installedapp, R.id.textView1, applist);
setListAdapter(adapter);
}
How to get the icon of other applications (Android)
I tried this link but I did not get things solved. so can any one help me out. thanks!
try like this
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
Drawable[] icons=new Drawable[packs.size];
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
icons[i]= p.applicationInfo.loadIcon(getPackageManager());
}
try this:
Icon icon = p.applicationInfo.loadIcon(getPackageManager());
imageView.setImageDrawable(icon);
try this way make a class called packageinformation:
public class PackageInformation{
private Context mContext;
public PackageInformation(Context context){
mContext=context;
}
class InfoObject {
public String appname = "";
public String pname = "";
public String versionName = "";
public int versionCode = 0;
public Drawable icon;
public void InfoObjectAggregatePrint() {//not used yet
Log.v(appname,appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList getPackages() {
ArrayList apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i
public ArrayList<InfoObject> getInstalledApps(boolean getSysPackages) {
ArrayList<InfoObject> res = new ArrayList<InfoObject>();
List<PackageInfo> packs = mContext.getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
InfoObject newInfo = new InfoObject();
newInfo.appname = p.applicationInfo.loadLabel(mContext.getPackageManager()).toString();
newInfo.pname = p.packageName;
newInfo.versionName = p.versionName;
newInfo.versionCode = p.versionCode;
newInfo.icon = p.applicationInfo.loadIcon(mContext.getPackageManager());
res.add(newInfo);
}
return res;
}
}
tuck this away somewhere and now to access the info from your working Activity class do this:
PackageInformation androidPackagesInfo=new PackageInformation(this);
ArrayList<InfoObject> appsData=androidPackagesInfo.getInstalledApps(true);
for (InfoObject info : appsData) {
Toast.makeText(MainActivity.this, info.appname,2).show();
Drawable somedrawable=info.icon;
}