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

前端 未结 6 2098
故里飘歌
故里飘歌 2021-02-10 14:13

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:49

    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();
    }
    

提交回复
热议问题