Android App Programming 2017-2018
Lab 3: Using web services

In this lab, you will learn how to interact with existing web APIs in an Android app.

Remember:

1. Internet Chuck Norris Database

Create an app with an activity containing a TextView and a button. On each press of the button, fetch a new random Chuck Norris fact from the Internet Chuck Norris Database (ICNDB)'s web API and display it in the TextView.

2. Chuck Norris Memes

Extend your app by embedding each Chuck Norris fact into an image from memegen.link.

For that, you'll first fetch a fact from ICNDB. Then, you'll select a template from memegen.link, in which you then embed the ICNDB fact. After receiving the link to the image from memegen.link, you display it inside an ImageView (you can find it in your activity_main.xml views - it is under Common View in the Design of the layout).

You can use the image library Picasso. Load it in your dependencies by adding the line

implementation ‘com.squareup.picasso:picasso:2.5.2’ 

Then in your code load the image using the following command

 Picasso.with(link to your main activity).load(an image url).into(an ImageView);

Here's an example of such an image:

Chuck Norris' first job was as a paperboy. There were no survivors.

back to the course web site





FR - FR - FR



L'objectif est d'apprendre comment interagir avec les APIs web existantes dans une application Android.

Rappel :

1. Internet Chuck Norris Database

Créez une application avec une activité contenant un TextView et un bouton. À chaque pression sur le bouton, récupérez un nouveau "joke" aléatoire lié à Chuck Norris à partir de la base de données Web Internet Chuck Norris Database (ICNDB) et l'afficher dans le TextView.

2. Chuck Norris Memes

Étendez votre application en intégrant chaque joke de Chuck Norris dans une image à partir de memegen.link.

Pour cela, vous allez d'abord récupérer un joke de ICNDB. Ensuite, vous sélectionnez un "template" dans memegen.link, dans lequel vous intégrez le joke de ICNDB. Après avoir reçu le lien vers l'image de memegen.link, vous l'affichez dans un ImageView (vous pouvez le trouver dans vos Views activity_main.xml - c'est une Common View dans le Design de votre layout).

Vous pouvez utiliser la lib d'images Picasso. Chargez-la dans vos dépendances en ajoutant la ligne

implementation'com.squareup.picasso:picasso:2.5.2' 

Puis dans votre code, chargez l'image en utilisant la commande suivante :

 Picasso.with(liens vers votre activité principale).load(an image url).into(an ImageView);

Voici un exemple :

Chuck Norris' first job was as a paperboy. There were no survivors.

back to the course web site