Détecter si l’application est en mode debug
isDebug, isDebuggable, ifDebug, ifDebuggable
vendredi 13 août 2010
par
popularité : 4%
par
popularité : 4%

Permet de savoir si l’application est en mode debug ou non. (retourne un booléen true|false).
Pour activer le debug de votre application, vous pouvez utiliser l’attribut Manifest.xml > android:isdebuggable=true|false.
public static boolean isDebug( Context context ) {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = new ApplicationInfo();
try {
ai = pm.getApplicationInfo( context.getPackageName(), 0 );
} catch( NameNotFoundException e ) {
ai = null;
return false;
}
if( (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE ) {
return true;
}
return false;
}
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = new ApplicationInfo();
try {
ai = pm.getApplicationInfo( context.getPackageName(), 0 );
} catch( NameNotFoundException e ) {
ai = null;
return false;
}
if( (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE ) {
return true;
}
return false;
}

Commentaires