common_blackbird_gallery.png

Good news if you are an Android App developer and you want to include functions of Ornithopedia!

Since version 1.3.1 (2016.01.18) you can call the species overview of Ornithopedia from your App. You can do this in 3 easy steps. First make sure the user has Ornithopedia installed. Second check if Ornithopedia is at least Version 1.3.1 and third call Ornithopedia with an Intent that has the scientific name attached. Should you use this method, I'd love to hear from you. Should you require something else (say you want a result from the activity or a different Ornithopedia activity)write in

 

 

 

Use this to check if Ornithopedia installed:

private boolean isPackageInstalled(Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo("org.ornithopedia.Europe", PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return false;
    }
}

Calling Ornithopedia with the method below on a version lower than 1.3.1 will cause an android.content.ActivityNotFoundException. Catch and handle this as you see fit (e.g. ask the user to update). With this in mind you have to call Ornithopedia via an intent and attach a string  named"latin_name" with the value of a scientific name of a species. The scientific name is a two word name, where the first letter of the first word is capitalized (e.g. "Turdus merula"). You can download a list of all valid scientific Latin names (with their English translation) here.

private void callOrnithopedia(String scientificName) {
    Intent intent = new Intent();
    intent.setComponent(
      new ComponentName("org.ornithopedia.Europe", "org.ornithopedia.Europe.Primary.SpeciesOverview"));
    intent.putExtra("latin_name", scientificName);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
    e.printStackTrace();
    }
}

Possible errors: If your users should report a Toast message "No species given." then you forgot to attach the "latin_name" string to the intent. Should they report "Unknown species:  [species]" then the string value [species] you have set is unknown (possibly misspelled).