答案 0 :(得分:1)
没有直接的方法可以从设置中读取此信息。但是,您可以从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
它将返回:
WhatsApp Inc.