Skip to main content

WP Android App using REST and volley part2

In last part of WP Android App using REST and volley tutorial we have learned to set up the basic UI of our WP app. In this part we will learn how to implement the below two features for our WP app.

  • Retrieve the sort description of the post and show in WP app

  • Show the featured Image in WP app

So first we will start by retrieving the short description of the post and show that description in our WP app.

In last tutorial we only show the title of the post, but we know showing only short title will not describe the post very well, so we should show some short description about the post. For this we don't need to do much work just need to retrieve the excerpt tag from the JSON Object that we have already fetched during retrieving the list of all post for our WP android App.

Below is the link of the series or Article of WP android App

Get the excerpt content from JSON Object

For getting the excerpt from the post list JSON Object and store it in variable we need to follow the below steps.

First of all we need to add new variable in our file and set the get and set method.

String excerpt;
public String getExcerpt() {
return excerpt;
public void setExcerpt(String excerpt) {
this.excerpt = excerpt;

Now retrieve and set the value of excerpt into variable using below two-line of code, below code we have to add in the same method where we retrieve the title of the post.

//Get excerpt
JSONObject exerptObj=obj.getJSONObject("excerpt");


Further, we have to show that value in our app also, so we need to add a TextView to the our PostItem layout xml file as given below.

android:visibility="visible" />


At last we need to update our post item adapter file that is file, add the below line in our VideoViewHolder and declare the variable.

protected TextView vExcerpt;
vExcerpt=(TextView) v.findViewById(;

Then set the value to our text view.



Important point to notice here is, we are setting the Html.fromHtml inside setText method , it is because excerpt are returned in the html format.

Get the featured Image of the Post in WP App

So far we have done with basic layout of the our WP App and now we want to set the featured image of the post to make it more attractive.

So for adding the featured Image we need to do two work.

  • First retrieve the featured Image

  • Set the featured image into the post

So for retrieving the featured image we need to modify getPost method of file as given below.

Here we suppose that you have already added a variable in our file to store the featured Image Url like below.


String postImg;
public String getPostImg() {
return postImg;
public void setPostImg(String postImg) {
this.postImg = postImg;


For retrieving the featured image first we need to get the Url of the featured JSON Url and then we need to retrieve that json


JSONObject featureImage=obj.getJSONObject("_links");
JSONArray featureImageUrl=featureImage.getJSONArray("wp:featuredmedia");
JSONObject featureImageObj=featureImageUrl.getJSONObject(0);
String fiurl=featureImageObj.getString("href");


Retrieve the JSON and store the URL into the respective position in list.


if(fiurl!=null) {
Log.d(TAG, featureImageObj.getString("href"));
final int id=i;

JsonObjectRequest getMedia = new JsonObjectRequest(Request.Method.GET,
fiurl, null,
new Response.Listener<JSONObject>() {
public void onResponse(JSONObject response) {
try {
Log.d(TAG, response.getString("source_url"));
} catch (JSONException e) {

}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Log.d(TAG, error.toString());



After the above change we are successfully get the URL of our featured image and we need to set that into our imageview by modifying the our post adapter class as given below.


.listener(new RequestListener<Drawable>() {
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {

Log.e(TAG, "Load failed", e);
for (Throwable t : e.getRootCauses()) {
Log.e(TAG, "Caused by", t);
return false;

public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
.into(((VideoViewHolder) holder).vImage);


Now our WP android app will look like as given below.

WP android app

If you have not read the first post of creating the WP Android App then you can first have look on below WP android app using REST and Volley.



  1. […] Next PostWP Android App using REST and volley part2 […]

  2. Full Source Code Please

  3. Hi Rakha,

    you can find the source code at below link.

    Let me know in case of any further issue.


  4. Thanks a lot bro Pawan Kumar.
    Have a great day!

  5. How to get featured image of post using retrofit??

  6. In reply to Sagar Sharma.
    Refer the below tutorial:-

    // getting URL of the Post fetured Image
    JSONObject featureImage=obj.getJSONObject(“_links”);
    JSONArray featureImageUrl=featureImage.getJSONArray(“wp:featuredmedia”);
    JSONObject featureImageObj=featureImageUrl.getJSONObject(0);
    String fiurl=featureImageObj.getString(“href”);

  7. You wrote this post with great care and attention to detail regarding this issue. Your article provided me with useful information. It's quite beneficial to me as well as others. Mobile App Development Company In Melbourne

  8. Nice job, this is essential information that is shared by you. This information is meaningful and factual for us to increase our knowledge about it. Always keep sharing this type of information. Website Design Ireland


Post a Comment

Popular posts from this blog

Flutter How to Start Android Activity from Flutter View

Flutter and Dart is an excellent combination for creating the UI, but for accessing the platform-specific service we need to open platform-specific activity. So lets in this article we will explore how to start an android activity and access the service from Flutter View. Create a Project for this Android Activity Flutter View Demo Create a Project From File menu select the New Flutter Project Enter the project name Select the AndroidX support and click on next After the above, we step click on Finish We will have the following project structure created. Create the Second Activity in Android Just go to the android folder and open it in separate windows. We will have the following project structure. Create the Activity Just right-click on the Kotlin folder and create a blank activity from the menu. If you create the activity then you may be required to upgrade the Gradle and do some import. So Just click on update and wait for the project s

WordPress Android App with REST API And Retrofit

Retrofit is the library which converts your JSON data into Java object. In this tutorial, we will learn about how to implement the Retrofit to create a WordPress Mobile App. As we all know, WordPress is the one of the biggest CMS (Content Management System) of the world. Wordpress full fill the requirements for all most every type of the website. So, in this tutorial, I am going to learn how to create an Android App using the WordPress REST API and Retrofit. What is Retrofit? If you want to know about Retrofit, I would like to give you just a simple one-line explanation of the Retrofit. It is a library which converts your REST HTTP request to Java interface. We will learn how we can do all these stuff using some very simple steps. Further, you can check the Retrofit Library here . So, In this tutorial, we will use the Retrofit to retrieve all post and there except ( A short Description of Post) form a WordPress website. Prerequisite for using the Retrofit for WordPress Android App Ther

Flutter State Management With Provider and ChangeNotifier

Flutter state management with provider library and why it's so important? There are lots of topics in flutter which are very important but out of those state management of your flutter application is the most important and little bit complicated as well. So in this article, I will try to explain how to use the provider package for managing the state of flutter and dart application and how to access the data down the hierarchy of the widget tree without recreating the whole UI. Basic knowledge of the state management and data flow in the Flutter Before starting the coding I would like to explain some basics about the Flutter application so that you can understand, why it's important to manage the state of your application in the correct way. In Flutter, everything is a widget and whenever the state of your application changes the UI is recreated the UI with the new data. Let's list out the topic or problem that we are going to explore about state management. Challenge o