Skip to main content

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 SHARINGetc. 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.

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.

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.

Comments

Popular posts from this blog

web2apk

http://web2apk.com/create.aspx Create App   Intro   About   Changes   MalWare ?   Contact   Privacy Useful Links Bluetooth Mini Keyboards Android Mini PC Reset Android URL App Title Icon or

how to retrieve image from sqlite database in android and display in listview

 Android platform provides several ways to store data in our application. 1. SQLite database 2. SharedPreferences etc For our post, we will only work with SQLite database. First and foremost, we need to understand what an SQLite database is? SQLite database  is an open source SQL database that stores data to a text file on a device. It executes SQL Commands to perform a set of functions, that is, create, read, update and delete operations. On my previous post, I showed how to  store data in SQLite database from edit text, retrieve and populate it in a listview . For this post, I will show the SQLite CRUD operations with images from gallery and text from EditText. We need to understand this; images are stored in SQLite database as BLOB data type. A BLOB is a large binary object that can hold a variable amount of data.  Note, we can only store images in the database as BLOB data type. We need to convert our image path to a bitmap then to bytes. Also

Android Bar Chart Using MpAndroidChart Library Tutorial

https://www.numetriclabz.com/android-bar-chart-using-mpandroidchart-library-tutorial/ Android Bar Chart Using MpAndroidChart Library Tutorial Objective In this tutorial we learn how to implement Bar Chart using MpAndroidChart Library in your Android App. Download Source Code       Step 1 Contents ·        1  Introduction ·        2  Creating Bar chart o    2.1  Create a new Project o    2.2  Adding library in Project o    2.3  Create Layout o    2.4  To Plot Bar Chart §   2.4.1  Initialize the graph id §   2.4.2  Creating a Dataset §   2.4.3  Defining X-axis labels §   2.4.4  Set the data §   2.4.5  Add the description to the chart §   2.4.6  Run your App §   2.4.7  Set the color §   2.4.8  Adding Animations o    2.5  To plot grouped bar chart §   2.5.1  Creating Dataset o    2.6  Get the best of Android plus exclusive deals and freebies in your inbox!