Collapsibile list of android application in my device? - android

Starting from this code
class PackageInfoData{
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
}
private void getInstalledPackages() {
ArrayList<PackageInfoData> installedApps = getInstalledApps(false); /* false = no system packages */
for (int i=0; i<installedApps.size(); i++) {
Log.i("Instlled app","APp Name:"+installedApps.get(i).appname+"package:"+installedApps.get(i).pname);
}
return installedApps ;
}
private ArrayList<PackageInfoData> getInstalledApps(boolean getSysPackages) {
ArrayList<PackageInfoData> res = new ArrayList<PackageInfoData>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
PackageInfo p = packs.get(i);
if ((!getSysPackages) && (p.versionName == null)) {
continue ;
}
PackageInfoDatanewInfo = new PackageInfoData();
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;
}
That returns a list of applications installed in the device, i want that this list is collapsibile. So for example, i have a button and when i click it the list will appears and when i click again the button the list disappears. How can i do it?

Related

Getting the app names and app icons of android non-system apps

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

Is there a way to read the name of all the apps and their sizes installed in Android?

I was trying to see how much size my app is taking and log it.
I know I can check the size of folder where I store data but is there any way to know all apps installed and their size?
By using the packageManager you can get all installed apps
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(TAG,appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
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;
}

Get Android application package name from android app labels?

Is there any way to get package names using the app name? For example, if I type whatsapp and the app is installed on device, then it should return the package name like com.whatsapp
Try this
public static void installedApps()
{
List<PackageInfo> packList = getPackageManager().getInstalledPackages(0);
for (int i=0; i < packList.size(); i++)
{
PackageInfo packInfo = packList.get(i);
if ( (packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
{
String appName = packInfo.applicationInfo.loadLabel(getPackageManager()).toString();
Log.e("App № " + Integer.toString(i), appName);
// use if(appName.equals(YOUR_APP_NAME))
}
}
}
You can get app name, pakage name, app version name, app version code, app icon.
Create a Modal class for all this (Data Structure)
ModalApps.java
public class ModalApps {
public String appname = "";
public String pname = "";
public String versionName = "";
public int versionCode = 0;
public Drawable icon;
}
Now getPackages() will return info of all packages
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
Now
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
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;
}
Using this ArrayList you can create package name corresponding to the app name.

Launcher Name Of Installed Apps

I have to get list of installed apps from android device . I am able to get the list. But there is some problem in getting the launcher name (which is defined in launcher activity tag in manifest not in application tag) of applications from the PackageInfo object. How to get the launcher name of installed apps from the PackageInfo object.??
I have tried in this way
packageInfo.applicationInfo.loadLabel(packageManager)
But this is not giving launcher name. It is giving the application tag string.
Use the following code to get the launcher activity of all packages:
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
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;
}
If you want the applications that handle the launcher, then you can look for applications that handle the intent filter Intent.CATEGORY_HOME with the PackageManager.

how to make a list of installed apps clickable?

Okay i managed to make a button list all installed applications like this:
public void launcher(View v){
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
myMenu.this.startActivity(mainIntent);
So when I click the button a window pops up like a dialog and lists all the applications. However, when I click any of the applications the dialog closes and nothing happens. how can I make these applications clickable?
Code would be preferrable and I'm a noobie so please be specific in your answer.
Thanks! :)
Here i am give one example which basically get all information of all install app from your device.
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
private ArrayList<PInfo> getPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
return apps;
}
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
ArrayList<PInfo> res = new ArrayList<PInfo>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
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;
}

Categories

Resources