Showing posts with label Check for Debbugable flag programitically. Show all posts
Showing posts with label Check for Debbugable flag programitically. Show all posts

Wednesday, June 29, 2011

Check for Debuggable flag in Android

Many a times we as a programmers want to hard code some values in our application for test purpose.

AND MOST OF THE TIMES WE FORGET TO REMOVE THEM WHEN WE RELEASE THE APP.

Well, to overcome this issue, i am posting a small snippet of code. Using this you can remove this issue just by checking for a flag before your hard coded values. ;P

/*
 Copyright [2011] [Abhinava Srivastava]

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */


public static boolean isDebugMode(Activity context){
boolean debug = false;
PackageInfo packageInfo = null;
try {
packageInfo = context.getPackageManager().getPackageInfo(context.getApplication().getPackageName(),
PackageManager.GET_CONFIGURATIONS);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo != null) {
int flags = packageInfo.applicationInfo.flags;
if ((flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
debug = true;
}else
debug = false;
}
return debug;
}

So now in your application just check for the return value of this function :)