Check whether an app on debug mode.

Here is a simple method to check whether an app is on debug mode or not. This will be useful to check to enable Strict Mode or to disable Strict Mode.

public static boolean isDebugMode(Context context) {
              PackageManager pm = context.getPackageManager();
try {
             ApplicationInfo info = pm.getApplicationInfo
p (context.getPackageName(), 0);
              return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
} catch (NameNotFoundException e) {

}
             return true;
}

And to enable Strict Mode,

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDialog()
.build());

The above code will detect all types of network and disk I/O. Very helpful for debugging.


Comments

Popular posts from this blog

There was a problem saving your changes. Please try again later.

Fatal: LoadModule: error loading module 'mod_sql_mysql.c'