WordPress to Android App using WP REST API Tutorial

Hello, guys welcome to WordPress to Android App Tutorial. In past few years WordPress has grown so much. It is the most popular blogging platform as more than 60 million websites are running on it.

WP REST API is one of the best features added to WordPress. It allows developers to create apps that can easily integrate with WordPress platform. Using this API we can easily retrieve our WordPress site’s data like posts, media, users, etc in JSON format by just sending HTTP request.

So in this tutorial I will teach you to make a very basic Android app for WordPress blog or website using WP REST API.

Note: This tutorial is about creating a very basic Android APP using WP REST API. If you are looking for a complete app with all the standard features like, PUSH NOTIFICATION, BOOKMARKS, SOCIAL SHARING etc. Then you can buy it from us. To get the Android App for your WordPress Blog CLICK HERE.

WordPress to Android App using WP REST API Video Demo

You can check this small video clip demonstrating the final output of this WordPress to Android App Tutorial.

Now, if you want to make the same then lets begin our tutorial.

How to work WP REST API?

  • To use WP REST API we require following two plugins. So first install these plugins in your wordpress blog.

Installing REST API Plugins

WordPress REST API (Version 2)

REST API – Filter Fields

Just go the links that I have given above to download and then install these plugins on your blog.

Fetching All Post of Your Website

  • You can fetch information about all the post on your blog by following URL.

http://your-blog-url/wp-json/wp/v2/posts

  • For a real example you can see the URL with my blog. Just go to the following link

http://www.thejavaprogrammer.com/wp-json/wp/v2/posts

  • You will see the following JSON Data.

wordpress to android app tutorial

Fetching Specified Number of Post

  • For fetching specified number of posts you can use post-per-page filter. The below URL will fetch only 3 posts.

http://your-blog-url/wp-json/wp/v2/posts?filter[posts_per_page]=3

Fetching Particular Post

  • You can fetch any particular post by its id.

http://your-blog-url/wp-json/wp/v2/posts/67

  • Here 67 is the id of the post.

Filtering Fields

  • As you have seen in above JSON data that there are several fields that we don’t require. So with the help of REST API – Filter Fields plugin you can filter few fields. For example you want to fetch only post’s id and title then it can be done by using following URL.

http://your-blog-url/wp-json/wp/v2/posts?fields=id,title

  • You can also fetch other fields along with id and title by just adding them in the URL. Like if you want to fetch id, title and content then it can be done using following URL.

http://your-blog-url/wp-json/wp/v2/posts?fields=id,title,content

  • Just make sure you use valid field name.

I hope now you got basic idea of using WP REST API. You can learn more about it by reading API documentation at below link.

http://v2.wp-api.org/reference/

How to Make Android App for WordPress Blog

Below I have shared the example for making simple app. In this app I have fetched titles of some posts and displayed them in a list on one activity. When you will click on any title then it will open another activity and display the title and content of that particular post.

For fetching the data from internet I have used Volley library. If you don’t know how to use it then I would recommend you to read below tutorial.

Android Volley Tutorial to Get JSON from Server

Creating WordPress to Android App Project

  • Open Android Studio and Create a new Project.
  • We need the following dependencies to be added in our app level build.gradle file.

  • Add internet access permission by adding following line in AndroidManifest.xml file.

  • First we will create a ListView in our activity_main.xml. In the ListView we will show all the latest post fetched from the REST API.

  • Now create a new file named post.xml inside your layout directory and write the following code.  This file will be used to show the selected post.

  • Now come inside MainActivity.java and write the following code.

  • Now create a new Activity to display the selected post. I have created Post.java

  • Now you can run your application. Just make sure that you have changed the URLs with your own blog and installed the REST API plugin correctly.
wordpress to android app tutorial
WordPress to Android App
  • Try clicking on one of the post and you will see the complete post.
wordpress to android app tutorial
WordPress to Android App
  • So our app is working fine. Yes we still need to work on improving the UI design, but this tutorial meant to explain you the concept. Now you can do whatever you want with your apps UI.
  • You can also download the source code of this WordPress to Android App Tutorial from the link given below.

If you have any queries regarding this WordPress to Android App Tutorial, then ask them in comment section. I will try my best to help you.

42 thoughts on “WordPress to Android App using WP REST API Tutorial”

  1. How to show images in a list view rows as well because only text is shown.
    How to fetch it from WordPress blog and show into android list view.

    Reply
  2. To get image you must first set featured image for each post. Now when you fetch the json data for a post, it will contain a key with name “featured_media”. This key’s value contain the id for the media used in that post. Now using this id fetch data for media by URL “http://www.thejavaprogrammer.com/wp-json/wp/v2/media/77”, replace 77 at the end with media id. This will give a json data for media that contains urls of images used in that post with different sizes. Get url from that data and fetch image from that url. You can show this image in listview with title.

    Reply
    • Hi Neeraj, I also have this problem of showing images in listview by getting the image from json output. I’ve researched other blogs but it is very complicated using arrays and adapters. I can’t modify your code using their technique because I’m just a newbie in programming. Can you make another tutorial using your code to put images on listview? Thanks!

      Reply
  3. hi, i have tried your code by there is problem , it shows “Some error occurred” and always loading spinner. what is the error ?

    Reply
    • Hey, the same error I’m getting when i tried this code. Can you please let me know steps to solve this issue? Is there anything we have to configure in one of those plugin that we integrate in WordPress or it is something else?
      Do let me know ASAP. Mail Id: developerPurvik@gmail.com

      Reply
  4. works great except…. Umlauts! Don’t know why, but the german umlauts are being displayed correctly in the main activity (list of post titles). But in the post activity (post content) they are not displayed correctly. Totally unreadable if the text is german.

    Reply
  5. I have configured this as per shown here. But I;m getting Error every time when request calls. It also doesn’t display any error log when i tried with the vollyError().getMessage(). Please provide some info ASAP. Awaiting reply.

    Reply
  6. Thank U so much for this tutorial!

    You can have a tutorial about webview wordpress in app. because use API, Content display not correct.

    Thank so much again!

    Reply
  7. how to parse this according mapPost.get(“???”);

    “wp:featuredmedia”: [
    {
    “embeddable”: true,
    “href”: “http://zimmedarnews.com/wp-json/wp/v2/media/21560”
    }
    ],

    Reply
  8. Thanks for this Fantastic tutorial.

    Please,

    is there any other way of displaying the “content” aside from using the webview??
    in such a scenario how do i deal with images embedded within the “content”??

    Reply
  9. I also need your assisance i’ve got a nested JSON Object Array as show below.


    },
    “terms”: {
    “category”: [
    {
    “ID”: 2,
    “name”: “Entertainment”,
    “slug”: “entertainment”,
    “description”: “And those who were seen dancing were thought to be insane by those who could not hear the music.”,
    “taxonomy”: “category”,
    “parent”: null,
    “count”: 30,
    “link”: “category/entertainment/”
    }
    ]

    How do i deal with this kind of case?

    Reply
  10. Hey can you please help me getting the tag names for each post from json results in android. I am able to get the title content and website etc, but getting the tags is not working.

    Reply
  11. I would like to write a web service for my mobile application in Php so what hash type password should I use to connect with my wordpress website. Since WordPress does not use normal MD5 or Salt for encrypting passwords.

    Reply
  12. how to integrate firebase cloud messaging with wordpress so that when i create a new post i will also get push notification on my app.

    Reply
  13. Hello Belal ,

    I am using WP REST API to getting data from android side, but data will take more time, i have use retrofit method for android side and data will come in json format.

    How it is possible and what is the reason for this ?
    1. It is possible for data will in large amount so the problem will accure ?

    So please give me the suggestion for this ASAP….

    Reply
  14. Hi, I got the source code and compile it using android studio. when the app was launched it has an error massage: Unfortunately, WordPress App Example has stopped. Please help. Thanks.

    Reply
  15. Hi! thanks I solved it already. The “+ id +” has spaces so I just deleted the spaces. I edit it to “+id+” and it worked! Thanks! My problem now is how to add categories. Do you have a post on how to make the categories on this app?

    Reply
  16. Hi Neeraj, I also have this problem of showing images in listview by getting the image from json output. I’ve researched other blogs but it is very complicated using arrays and adapters. I can’t modify your code using their technique because I’m just a newbie in programming. Can you make another tutorial using your code to put images on listview? Thanks!

    Reply
  17. please can you explain how to create new post with wordpress
    API or how to create a new comment on a post using android volley?

    Reply
  18. Hello, in my post content there are Javascript functions, function that make a pop up when clicking a button, despite that i enabled Javascript for my WebView, in the logs i get an an error that the js function is not defined. How can i handle this?
    Thanks.

    Reply
  19. hello does anyone have the kindness to help you add images to the ListView? because it is impossible and we are many to have managed with voyre code to make the application but we can not add the images featured media to post

    Reply
  20. Its showing unchecked cast java.lang.object..for

    mapPost = (Map)list.get(i);
    mapTitle = (Map) mapPost.get(“title”);
    postTitle[i] = (String) mapTitle.get(“rendered”);
    }

    Please help

    Reply

Leave a Comment