Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to determine whether an Android application is signed for production or debug at runtime?

Is there a way to determine whether an Android application is signed for production or debug at runtime?

like image 722
TacB0sS Avatar asked Dec 05 '22 18:12

TacB0sS


1 Answers

private static Boolean isDebugBuild = null;
    protected boolean isDebugBuild() {
        if(isDebugBuild == null) {
            PackageManager pm = getPackageManager();
            try {
                PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
                isSignedWithDebugKey = (pi.applicationInfo.flags &
                    ApplicationInfo.FLAG_DEBUGGABLE) != 0;
            }
            catch(NameNotFoundException nnfe) {
                nnfe.printStackTrace();
                isDebugBuild = false;
            }
        }

        return isDebugBuild;
    }

Since ADT 8, if you don't specifically add debuggable="true" to your manifest, debug builds will have it set to true, and exported / signed builds will have it set to false.

It sounds like this is might be a more reliable method (as long as you don't manually set debuggable..) to determine if it is a debug vs release build, but not specifically if the certificate was a debug cert - which was your question, so my answer might not be relevant for you.

like image 122
FunkTheMonk Avatar answered Dec 31 '22 18:12

FunkTheMonk