Programmatically read debug state in manifest

I want to read the debug state in the Android manifest file, and then disable the method or not based on this state. I see you can read the XML file and parse it, but this method seems not so elegant. Is there any other way, this is information about what is in the manifest stored in a Java object somewhere?

<application android:name=".MyActivity" android:icon="@drawable/myicon"
    android:label="@string/app_name" android:debuggable="true">
+5
source share
2 answers
boolean DEBUGGABLE = (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
+17
source

I use ApplicationInfo.FLAG_DEBUGGABLE to check if android: debuggable = true is set. The following code is copied from this stream

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

All Articles