How to check if APK is signed or “debug build”?

后端 未结 10 1930
我在风中等你
我在风中等你 2020-11-29 16:34

As far as I know, in android \"release build\" is signed APK. How to check it from code or does Eclipse has some kinda of secret defines?

I need thi

10条回答
  •  时光取名叫无心
    2020-11-29 16:46

    Solution in Kotlin that I'm using at the moment:

    @SuppressLint("PackageManagerGetSignatures")
    @Suppress("DEPRECATION")
    fun isSigned(context: Context?): Boolean {
        return (context?.packageManager?.getPackageInfo(context.packageName, PackageManager.GET_SIGNATURES)?.signatures?.firstOrNull()?.toByteArray()
                ?.let {
                    return@let CertificateFactory.getInstance("X.509").generateCertificate(ByteArrayInputStream(it))
                } as? X509Certificate)
                ?.issuerDN
                ?.name
                ?.contains("O=Android", ignoreCase = false) ?: true
    }
    

    that way I can still SIGN in debug and those will be reported to Crashlytics (example, for the QA process)

提交回复
热议问题