In my Android application, I wanted to check the installation source of the application. I looked at the Android documentation and found the following API as part of the PackageManager class:
abstract String getInstallerPackageName(String packageName)
Get the package name of the application that installed the package.
Then I used the following code in the onCreate MyActivity method:
if(Build.VERSION.SDK_INT >= 11) { PackageManager myapp= this.getPackageManager(); String installer = myapp.getInstallerPackageName("com.MyPackage"); if(installer == null) { Toast.makeText(getApplicationContext(), MyActivity.this.getString(R.string.invalidsource), Toast.LENGTH_SHORT).show(); MyActivity.this.finish(); } }
But it looks like this API is returning null on a real device.
Please let me know if we have other ways to get the application installation source.
source share