1

If anyone knows how to get developed organization name by using apk in android programmatically share your suggestions. FYI, I here by attached the image.

 This image I have marked the WhatsApp organization name, How to get this organization name programmatically by using apk.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
karthik
  • 321
  • 1
  • 8
  • 21
  • You can get a list of all PackageInfos by calling `getPackageManager.getInstalledPackages()`. Each `PackageInfo` has a String field, `packageName`, that appears to be what you are after. For example, for the above it would be `com.whatsapp`. – President James K. Polk May 07 '18 at 17:44

1 Answers1

1

There is no direct way to read this information from settings. However you can read this information from the signing certificate of the APK as follows:

 public String getOrganizationName(final String packageName) {
        String orgName = null;
        try {
            Signature signatures[] = getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures;                
            for (Signature signature : signatures) {
                final byte[] rawCert = signature.toByteArray();
                InputStream certStream = new ByteArrayInputStream(rawCert);

                try {
                    CertificateFactory certFactory = CertificateFactory.getInstance("X509");
                    X509Certificate x509Cert = (X509Certificate) certFactory.generateCertificate(certStream);
                    String issuerDn = x509Cert.getIssuerDN().getName();
                    int indexOfOrg = issuerDn.indexOf("O=");
                    int indexOfSeperator = issuerDn.indexOf(",", indexOfOrg);
                    final String organizationName = issuerDn.substring(indexOfOrg+2, indexOfSeperator);
                    if (orgName == null) {
                        orgName = organizationName;
                    }
                    Log.d("Test", "Organization Name: " + organizationName);

                } catch (Exception e) {
                     e.printStackTrace();
                }

            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return orgName;
 }

Call this method as follows:

getOrganizationName("com.whatsapp"); //You can use any installed package name

It will return:

WhatsApp Inc.

Sagar
  • 23,903
  • 4
  • 62
  • 62