如何通过编程方式使用apk获取开发的组织名称?

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

如果有人知道如何在 android 中使用 apk 以编程方式获取开发的组织名称,请分享您的建议。仅供参考,我在这里附上图片。

无法直接从设置中读取此信息。但是,您可以从 APK 的签名证书中读取此信息,如下所示:

 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;
 }

调用此方法如下:

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

会return:

WhatsApp Inc.