Find out if a previously defined Android application has been installed.

I have an application that provides you with a list of various applications that you can download and install from the Play Store to earn positive results. Now I do not want the user to delete the previously installed application and download it again through my application and earn positive results.

Is there a way to find out if an application has been previously installed on a user device?

Update I'm interested in all installed and remote applications, regardless of when my application was installed. I don’t want to store any data about any application installations on my end, I want to know if this data is stored on the device somewhere for future use.

Note I am also interested in the applications that we deleted. Can I get this data?

+4
source share
2 answers

I see where you are trying to go, but I think you need to rethink the approach a bit. You should always allow your users to install and uninstall at their discretion. But you can put a check in the application to see when the application was first installed.

PackageInfo info = pm.getPackageInfo(packageName, 0);
long firstInstallTime = info.firstInstallTime;

, firstInstallTime .

PackageInfo .

, ( , ), :

ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
long mostRecentInstallTime = new File(appInfo.sourceDir).lastModified();

, 1- , " ", , .


:
...
PackageInfo , . PackageInfo , , , " ".
firstInstallTime :

// Get PackageInfo for each app on the device
List<PackageInfo> packageInfoInstalledPackages = getPackageManager().getInstalledPackages(0);

// Now iterate through to get the info you need.
long[] firstInstallTimes = long[packageInfoInstalledPackages.size()];
for(int i=0;i<packageInfoInstalledPackages.size();i++) {
    PackageInfo p = packageInfoInstalledPackages.get(i);
    if (p.versionName != null) {
        firstInstallTimes[i] = p.firstInstallTime;
    }        
}

ApplicationInfo, , .

+5

, ,

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List <ResolveInfo> pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);

for(ResolveInfo resolve : pkgAppsList)
{
    Log.d("MY_APP", resolve.toString());
}

, !

0

Source: https://habr.com/ru/post/1548341/


All Articles