How to make Android app automatically configure w/ debug vs. release values?

前端 未结 6 2155
情书的邮戳
情书的邮戳 2021-02-10 13:54

I\'m working on an Android app, specifically one that uses the Facebook Android SDK. In development mode, I\'m working with a test Facebook app that goes by one ID. However, i

6条回答
  •  一整个雨季
    2021-02-10 14:27

    I can't recommend the IMEI method... the main problem with it is that not all Android devices will have IMEIs. A better way is to examine the signature used to sign the .apk.

    // See if we're a debug or a release build
    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        if (packageInfo.signatures.length>0) {
            String signature = new String(packageInfo.signatures[0].toByteArray());
            isReleaseBuild = !signature.contains("Android Debug");
        }
    } catch (NameNotFoundException e1) {
        e1.printStackTrace();
    }
    

提交回复
热议问题