Android apps are installed from the .apk file which contains the code, resources and other stuff. Android api can provide some additional information related to app installation. I used these methods in my recently published app - Power Apk.

PackageManager is the class that can be used to retrieve installation information. To get an instance of PackageManager, you first need to have a Context available. In this short post I would like to highlight a couple of useful methods for getting installation info.

Get PackageInfo Object

PackageInfo class contains information about the package you've installed. A lot of the information comes from AndroidManifest.xml. You can use getPackageInfo() method of PackageManager class to retrieve a PackageInfo object. The first parameter is the package name you are interested in, and in the second parameter you can specify whether you want to retrieve additional information (e.g., info about Activities, Services, ...). I used 0 in this example because I didn't require anything additional. This is what I've put into my Activity (which inherits from Context)

...
    PackageManager pm = getPackageManager();

    try {
        PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);        
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

Get Installation Date and Last Update Date

The PackageInfo class field firstInstallTime contains the date when the app was installed. You can also find the date of the last update - lastUpdateTime. Both fields contain time information in the same units as System.currentTimeMillis(). You can use the following code to extract the date in human readable format

...
import java.text.SimpleDateFormat;
import java.util.Date;
...
public class InstallInfoActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PackageManager pm = getPackageManager();

        try {
            PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);

            SimpleDateFormat sdf =  new SimpleDateFormat("MM/dd/yyyy");
            String installDate = sdf.format(new Date(pi.firstInstallTime));
            String updateDate = sdf.format(new Date(pi.lastUpdateTime));

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
...

Find Installation Source/App Store

The PackageManager class contains another useful method - getInstallerPackageName(). If you installed the package through ADB, this method will return null. Otherwise it should return the package name of the installer application, which would be com.android.vending in case of Google Play.

// Get installer package name for current app
String ipn = packageManager.getInstallerPackageName(getPackageName());

Getting More Detailed Information with Power Apk App

There is much more information you cat get with the help of the aforementioned classes. If you want to see what's possible, you can download my Power Apk app. Once you tap on a specific app on the list, you'll get various additional information, such as signature details, activities and services list, minimal supported Android version, and much more.

You can Download Power Apk from Google Play

Next Post

Add a comment