How to get version any app in phone - android

I want to check any app version in phone ( android studio )
and if the last version equal the version install in users phones app
How to get any app version installed on the phone by Android Studio?

You need to iterate all application installed the app, then get each of the package name to get the package info.. in packageInfo have infomation about those app
final PackageManager packageManager = getPackageManager();
List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
List<String> vers = new ArrayList<>();
for (ApplicationInfo appInfo : installedApplications)
{
PackageInfo packageInfo = getPackageManager().getPackageInfo(appInfo.packageName, 0);
vers.add(packageInfo.versionName);
}
Log.i(TAG,vers.toString());

Get all install app info:
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 +" ver: "+packInfo.versionCode);
}
}
More info:Info

Related

Is it possible to get list of all the applications that user has installed?

Several games and apps show adds like install the app to get rewards. How does that function? Can I get the list of all the apps that user has installed on his device including uninstalled apps, how?
You can get list of installed non-system apps
public 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);
}
}
}

Android app listing permissions only

I am developing an android application that will display all the applications installed in the mobile phone and when clicking on a particular application, it should show only permissions of that application. I used package manager to fetch the details of all the details of the apk's installed.
The part of the code is here:
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> applist = packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it = applist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
PackageInfo pk1 = (PackageInfo) it.next();
if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
// Log.v("System app using internet = ",""+ pk.applicationInfo.loadLabel(packageManager));
String p = pk.applicationInfo.loadLabel(packageManager).toString();
if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.CAMERA, pk.packageName))
//results.add("" +"\n"+pk.applicationInfo.loadLabel(packageManager));
{
//Drawable appicon = getPackageManager().getApplicationIcon("com.google.maps");
results.add("" + "\n" + pk.applicationInfo.loadLabel(packageManager));
}
if (PackageManager.PERMISSION_GRANTED == packageManager.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, pk.packageName))
results1.add("" +"\n"+pk1.applicationInfo.loadLabel(packageManager));
}
}
I should get the icons followed by the application name while listing the applications.
Icon and application name example
How should I modify this code so that the required output is got.
Example app
Official document
core code:
packageInfo.requestedPermissions?.forEach { permission -> ... }
More links
https://developer.android.com/reference/android/Manifest.permission.html
https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/AndroidManifest.xml
http://androidpermissions.com/

Android : List all process which uses certain resources

I am new to android programming.
I want to list all the process which uses/access certain resources like :
File(s)
Internet etc
Any sample code or suggestion.
Thanks in Advance ...:)
You will get all application name which is using internet,
private ArrayList<String> getInstalledAppsWithSpecificPermission(Context context) {
ArrayList<String> appsPkgName = new ArrayList<String>();
PackageManager pm = context.getPackageManager();
List<PackageInfo> appNamelist = pm.getInstalledPackages(0);
Iterator<PackageInfo> it = appNamelist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.d("System Application which using internet = ", ""+pk.applicationInfo.loadLabel(pm));
continue;
}
if (PackageManager.PERMISSION_GRANTED == pm
.checkPermission(Manifest.permission.INTERNET,
pk.packageName))
results.add("" + pk.applicationInfo.loadLabel(pm));
}
Log.v("Application using internet = ", appsPkgName.toString());
return results;
}

Android:Getting List of Application's package info which has been installed as a Device administrator

I need to get the list of package info for application which has been installed as Device admin. The code you share should support from Adroid Api version 8.
The following code will give me the list of Downloaded apps info, but i need an extra filter in the list as the app should be Device admin enabled app
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);
}
Thanks in Advance
Here the solution :
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
List<ComponentName> activeAdmins = devicePolicyManager.getActiveAdmins();
if (activeAdmins != null){
for (ComponentName admin : activeAdmins){
admin.getPackageName();
}
}
We will get list of apps use this
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
}

Installed application is third-party or not

How can I get the list of installed third-party applications on Android phone.
I am able to get the list of application with the code below but I want only third-party applications.
PackageManager pm = context.getPackageManager();
appInstalModel.setAppName(p.applicationInfo.loadLabel(context.getPackageManager()).toString());
appInstalModel.setAppPkg(p.packageName);
appInstalModel.setAppVersionName(p.versionName);
List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for (int i=0; i < apps.size(); i++)
{
if ((apps.get(i).flags & ApplicationInfo.FLAG_SYSTEM) == 1)
{
//System app
}
}
RoflcoptrException's answer is correct. But in some cases it won't give you all the installed third-party applications. ApplicationInfo also has flag FLAG_UPDATED_SYSTEM_APP which is set
If this application has been install as an update to a built-in system
application
On my smart phone such applications include Amazone Kindle, Adobe Reader, Slacker Radio and others. These applications did not come with the phone and were installed from Google Play Store. Thus, they can be considered as third-party apps.
So, you may also want to check FLAG_UPDATED_SYSTEM_APP flag.
final PackageManager packageManager = _context.getPackageManager();
List<ApplicationInfo> installedApplications =
packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo appInfo : installedApplications)
{
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
{
// IS A SYSTEM APP
}
if ((appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)
{
// APP WAS INSTALL AS AN UPDATE TO A BUILD-IN SYSTEM APP
}
}
The ApplicationInfo object will have the FLAG_SYSTEM flag unset. The sdmove program might have some sample code.
small changes in #Roflcoptr answer.
List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for (int i=0; i < apps.size(); i++)
{
if ((apps.get(i).applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
{
//System app
}
}
Thanks #Roflcoptr for your answer.
public static List<PackageInfo> getInstalledAppList(Context context) {
ArrayList<PackageInfo> packList = (ArrayList<PackageInfo>) context.getPackageManager().getInstalledPackages(0);
showLog("/n/n ********************** App List ********************");
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(context.getPackageManager()).toString();
showLog(appName + "(" + packInfo.packageName + ")");
} else {
packList.remove(i);
i--;
}
}
showLog("List Size : " + packList.size());
showLog("/n/n ********************** END ********************");
return packList;
}

Categories

Resources