Skip to content

Commit

Permalink
Merge pull request #47 from bugsnag/prefer-passed-apikey
Browse files Browse the repository at this point in the history
Prefer passed apiKeys to manifest apiKeys
  • Loading branch information
loopj committed Jan 9, 2015
2 parents 10c42bd + 6e649fc commit 6ee9627
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;;
import android.content.pm.PackageManager;
import android.text.TextUtils;

/**
* A Bugsnag Client instance allows you to use Bugsnag in your Android app.
Expand Down Expand Up @@ -58,11 +59,13 @@ public Client(Context androidContext, String apiKey, boolean enableExceptionHand
// Get the application context, many things need this
appContext = androidContext.getApplicationContext();

// Attempt to load API key from AndroidManifest.xml
try {
ApplicationInfo ai = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(), PackageManager.GET_META_DATA);
apiKey = ai.metaData.getString("com.bugsnag.android.API_KEY");
} catch (Exception e) { }
// Attempt to load API key from AndroidManifest.xml if not passed in
if (TextUtils.isEmpty(apiKey)) {
try {
ApplicationInfo ai = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(), PackageManager.GET_META_DATA);
apiKey = ai.metaData.getString("com.bugsnag.android.API_KEY");
} catch (Exception e) { }
}

if(apiKey == null) {
throw new NullPointerException("You must provide a Bugsnag API key");
Expand Down

0 comments on commit 6ee9627

Please sign in to comment.