Reputation: 3497
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.
Upvotes: 4
Views: 3203
Reputation: 426
First, find Installer package name, like:
String sourceId = getPackageManager()
.getInstallerPackageName(getPackageName());
Then check the sourceId
variable's value, like:
com.android.vending
APK
, and installed again:com.google.android.packageinstaller
null
Upvotes: 6
Reputation: 3599
I use below code to check, if a apk was downloaded from a store or sideloaded:
private boolean isStoreVersion(Context context) {
boolean isStoreVersion= false;
try {
String installer = context.getPackageManager()
.getInstallerPackageName(context.getPackageName());
isStoreVersion= !TextUtils.isEmpty(installer);
} catch (Throwable e) {
e.printStackTrace();
}
return isStoreVersion;
}
Upvotes: 0
Reputation: 753
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
Upvotes: 2