How to get the app name of a recently installed app

I am finding that the app is installed on an android device using a broadcast receiver.

During the time that I found the app installed, I want to get the app name of that app.

I tried to search the web, but I can only find how to get all installed apps, can anyone help me?

+3


source to share


2 answers


With this code, you can get a list of installed applications and the latest date of installation and update of the package.



final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
    String packageName = packageInfo.packageName;
    String appFile = packageInfo.sourceDir;
    long lastModified = new File(appFile).lastModified();
    //Use this to get first time install time
    //long installed = context.getPackageManager().getPackageInfo(packageName, 0).firstInstallTime;
    Log.d(TAG, "Installed package :" + packageName);
    Log.d(TAG, "Source dir : " + appFile);
    Log.d(TAG, "Last Modified Time :" + lastModified); 
}

      

+1


source


I added some simple logic that will get the newly installed app (app name and package name).



        PackageManager pm = context.getPackageManager();
        List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

        long prev_modified = 0;
        packageName = null;
        appName = null;
        for (ApplicationInfo packageInfo : packages) {
            String appFile = packageInfo.sourceDir;
            long lastModified = new File(appFile).lastModified();

            //Use this to get first time install time
            //long installed = context.getPackageManager().getPackageInfo(packageName, 0).firstInstallTime;
            if (lastModified > prev_modified) {
                prev_modified = lastModified;
                packageName = packageInfo.packageName;
                appName = packageInfo.loadLabel(context.getPackageManager()).toString();

            }
        }

        Toast.makeText(context, packageName + "\n" + appName, Toast.LENGTH_SHORT).show();

      

+1


source







All Articles