0

I am developing an app which will contain a list of Apps. On click the user will be redirected to the Play Store to download this app. On successful download I have to send that apps package name to a server to validate it. How can I do that?

Jonas Köritz
  • 2,606
  • 21
  • 33
niraj
  • 95
  • 1
  • 10

3 Answers3

0

I assume you want to do this at runtime, so your app can read its own package_id w/o having this hardcoded. For that you need to use PackageManager's getPackageInfo() method:

protected String getPackageName() {
    try {
        PackageInfo packageInfo = getPackageManager.getPackageInfo(getPackageName(), 0);

        return packageInfo.applicationInfo.packageName;
    } catch (Exception e) {
        e.printStacktrace();
    }

    return null;
}
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • no not my own app info I want to get package name of app download via my app from play store – niraj Apr 21 '16 at 11:36
  • @niraj you need to rework your question as it is not clear. You said `I am developing an app which will contain a list of Apps.` - so if you got list of apps why not store Ids in that list too? – Marcin Orlowski Apr 21 '16 at 11:40
0

Use apkanalyzer, its part of the Android studio:

apkanalyzer manifest application-id path/to/apk/file.apk
michaelbn
  • 7,393
  • 3
  • 33
  • 46
0

When installing the application. ACTION_PACKAGE_ADDED
documentation
BroadcastReceiver method onReceive

val packageManager = context.packageManager
val uId = intent.getIntExtra(Intent.EXTRA_UID, -1)
val packageName = packageManager.getPackagesForUid(uId)?.first() ?: return

When uninstalled the application. ACTION_PACKAGE_FULLY_REMOVED or ACTION_PACKAGE_REMOVED
documentation

val packageName = intent.data?.schemeSpecificPart ?: return

Get app name or icon

val applicationInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
  packageManager.getApplicationInfo(packageName, PackageManager.ApplicationInfoFlags.of(0))
} else {
  @Suppress("DEPRECATION")
  packageManager.getApplicationInfo(packageName, 0)
}

val appName = packageManager.getApplicationLabel(applicationInfo)
val appIcon = packageManager.getApplicationIcon(applicationInfo)

Attention
When installing the application, if use intent.data?.schemeSpecificPart not on all devices the correct one is returned package name.

Arman
  • 25
  • 7