Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get Package information programmatically in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 5.39k
    Comment on it

    In some cases we have to get global information about application environment programmatically. We will get package name, version name, version code, application info and last updated time using the PackageInfo class which contains all of the information collected from Application. Some of the important fields are described below:

    tvPackageInformation = (TextView)findViewById(R.id.tvPackageInformation);
    
            try {
                packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
    
            // The name of this package.
            packageName = packageInfo.packageName;
    
            // The version name of this package, as specified by the <manifest> tag's versionName attribute.
            versionName = packageInfo.versionName;
    
            // The version number of this package, as specified by the <manifest> tag's versionCode attribute.
            versionCode = packageInfo.versionCode;
    
            // Information collected from the <application> tag, or null if there was none.
            applicationInfo = packageInfo.applicationInfo;
    
        // The time at which the app was last updated.
            lastUpdateTime  = packageInfo.lastUpdateTime;
            elapsed = ((System.currentTimeMillis() - lastUpdateTime) / 1000);
            lastUpdateTotalTime = String.format("%02d:%02d:%02d", elapsed / 3600, (elapsed % 3600) / 60, (elapsed % 60));
    
            tvPackageInformation.setText("Last Update Time:  "+lastUpdateTotalTime+"\n"+"Package Name:  "+packageName+
                    "\n"+"Version Name:  "+versionName+"\n"+"Version Code:  "+versionCode+
                    "\n"+"Application Info:"+applicationInfo);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: