Reputation: 9306
I want to read the debug state in the Android manifest file and then fire off a method or not based on that state. I see you can read the XML file and parse it but that way seems not that elegant. Is there another way, is that information of whats 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">
Upvotes: 5
Views: 3100
Reputation: 1090
i use the ApplicationInfo.FLAG_DEBUGGABLE for checking if the android:debuggable=true is set. The following code is copied from this thread
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;
}
Upvotes: 2
Reputation: 8251
boolean DEBUGGABLE = (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
Upvotes: 17