Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the app was installed by apk or not

I need to check the app was installed by apk or from google play.

I have an apk that was downloaded from google play, and also, the app was available on google play. I want to classify two cases.

I already read about this question below, but it is about which app store the application was installed by, And it was not I want.
How does android package manager know what to install from the market place web site?

Is there any method to check the app was installed by apk or not, programmatically by app itself? Any help will be appreciated.

like image 842
Stanley Ko Avatar asked Oct 27 '25 04:10

Stanley Ko


2 Answers

First, find Installer package name, like:

String sourceId = getPackageManager()
    .getInstallerPackageName(getPackageName());

Then check the sourceId variable's value, like:

  • If App was installed from Google play store, said value should be:
com.android.vending
  • If installed from Google play store, then extracted APK, and installed again:
com.google.android.packageinstaller
  • If download from Google play store publish, App release list:
null
like image 72
Anuj Zunjarrao Avatar answered Oct 30 '25 01:10

Anuj Zunjarrao


Try this one

PackageManager pm = getPackageManager();

if(pm.getInstallerPackageName(getPackageName()).equals("com.android.vending"){
   //App is from google play
   //do something
}

app with unknown source will return empty string

like image 40
Android_K.Doe Avatar answered Oct 30 '25 00:10

Android_K.Doe