androidapkandroid-applicationinfo

How to get the developed organization name by using apk programmatically?


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.


Solution

  • 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.