[Android Tips] 27. 检查 APK 是否可调试

使用 Android SDK 提供的 aapt 检查 APK 文件

$ aapt d badging ${APK_FILE} | grep 'application-debuggable'

检查自身

    /**
     * 判断当前应用是否是debug状态
     */
 
    public static boolean isApkInDebug(Context context) {
        try {
            ApplicationInfo info = context.getApplicationInfo();
            return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        } catch (Exception e) {
            return false;
        }
    }

检查其他应用

    /**
    * 检测其他应用是否处于debug模式。
    */
    public static boolean isApkDebugable(Context context,String packageName) {
        try {
            PackageInfo pkginfo = context.getPackageManager().getPackageInfo(
                    packageName, 1);
            if (pkginfo != null ) {
                ApplicationInfo info= pkginfo.applicationInfo;
                return (info.flags&ApplicationInfo.FLAG_DEBUGGABLE)!=0;
            }
            
        } catch (Exception e) {
            
        }
        return false;
    }
原文地址:https://www.cnblogs.com/shaobin0604/p/7111625.html