wordpress post in android app

The Simplest Way to Get WordPress Post in Android App

From last few days, people asked me- How to Get WordPress Post in Android App? WordPress is a most popular platform to host a blog. It has monthly 409+ million People view more than 19.6 billion pages hosted by WordPress platform. And this count is kept increasing day by day.

So In this blog, I will show you step by step process to get WordPress post in Android App. I will take help of two plugins that make all the content and resources on my WordPress blog accessible. WP REST API is an amazing feature on WordPress. It allows developers to create apps that can easily integrate with WordPress platform.

WordPress REST API for Android

First, you have to install WordPress Rest API v2 on your WordPress blog. Go to the Plugins–> Click ADD NEW –> type keyword WordPress rest. It is the official WP REST API plugin that will be used to fetch data from the blog.

WordPress REST API (Version 2)

Second, You have to install Rest API filter. Using this filter you can short your result like of you want only post id and title, so you can pass filter parameter as id, title.

WordPress REST API – Filter Fields



Fetching All Post of Your Website

  • You can fetch information about all the post on your blog by the following URL. It will return a JSON response that contains all the information about your blog.

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

for example http://www.blueappsoftware.in/android/wp-json/wp/v2/posts

 

Fetching Specified Number of Post

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

    http://your-blog-url/wp-json/wp/v2/posts?per_page=3

    for example http://www.blueappsoftware.in/android/wp-json/wp/v2/posts?per_page=1

Fetching Particular Post

  • You can fetch information about a particular post by using post ID.

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

for example http://www.blueappsoftware.in/android/wp-json/wp/v2/posts/1179

Use Filtering Fields

  • Rest API returns all the post information. I will create the problem of the slow start of the android app. 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 the following URL.

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

for example http://www.blueappsoftware.in/android/wp-json/wp/v2/posts/1179?fields=id,title,date

To know more about WordPress Rest API and Filter, Please check here

Watch Video Get WordPress post in Android App

Login & Download source code

download-code350-100

50 days android course

 

1) Install WordPress Plugins
2) Add Gradle Dependency
3) Add RecyclerView and CardView Layout
5) Make Retrofit Request to get JSON
6) Run App on device

Install WordPress Plugins

You have Installed both the WordPress REST API and WordPress REST filter API on you WordPress blog. Please remember to activate it.

Add Dependency on Gradle file

Create a new project on android studio. We have to app Internet Permission on AndroidManifest File. Also, add the dependency for Volley or Retrofit lib. If you don’t know how to use Retrofit to get data from web server please check how to get JSON data using Retrofit

Add Gradle Dependency



Add RecyclerView and CardView Layout

Now add RecyclerView on activity-main.xml and create an adapter for RecyclerView. Here you can see my blog post about RecyclerView. Create another layout name as postdetails.xml for adapter which will display Post Image, post title and post short description inside a cardview.

activity-main.xml

PostDetails.xml

 

Make Retrofit Request to get JSON

Create POJO model for Retrofit and a Retrofit API method to send a request to URL. To create POJO model you can use this online tool that auto create POJO model from JSON string. You can use this JSON Editor to see you JSON string in proper structure. Just past your complete JSON string in this editor and click on right arrow. Get all java file and layout by downloading the project for free. I added onclick listener on cardview, so when you will click on any post, I will open new activity with webview. The webview will display your complete post in mobile view, Because my WordPress blog has mobile view campatibility.

MainActivity.java

Retrofit API call

 


Run App on device

Now Run this code on the real device. You will see all your blog post title and description is in cardview. You can click on any one of the post to see complete post.

Please leave your comment about video lesson and what problem you are facing on android.

Read MoreGet JSON Data using Retrofit and Send FCM Notification to Device

50 days android course

Posted in andorid, WordPress and tagged , , , .

kamal bunkar

I Am Post Graduation (M.Tech. C.S.E) from VNIT, Nagpur. I Have Published Two Research Paper On International Journal. My Apps on Google Play Store- Sanyukt Parivar(Mp Police ), NOTOtag- Digital Chhindwara, The Tubby-VoiceRecognizer & More.
Contact me at kamal.bunkar@blueappsoftware.in

33 Comments

  1. I love your blog.. very nice colors & theme. Did you create this
    website yourself or did you hire someone to do it for you?
    Plz respond as I’m looking to create my own blog and would like to find
    out where u got this from. appreciate it

  2. Pretty great post. I just stumbled upon your weblog and wanted to say
    that I’ve truly loved browsing your blog posts.
    In any case I’ll be subscribing for your feed and I hope you write once more very soon!

  3. Hi there! This post could not be written any better!
    Reading through this post reminds me of my good old room mate!
    He always kept talking about this. I will forward this article to him.
    Fairly certain he will have a good read. Thank you for sharing!

  4. Hi there! Quick question that’s totally off topic.
    Do you know how to make your site mobile friendly?
    My weblog looks weird when browsing from my iphone4.
    I’m trying to find a template or plugin that might
    be able to fix this issue. If you have any recommendations, please share.
    Thank you!

  5. This is really attention-grabbing, You are an overly skilled blogger.
    I have joined your feed and look forward to in the hunt
    for extra of your great post. Also, I have shared your site in my social networks

  6. I’m really enjoying the theme/design of your blog.

    Do you ever run into any browser compatibility issues?

    A few of my blog audience have complained about my site not
    working correctly in Explorer but looks great in Chrome.
    Do you have any solutions to help fix this issue?

  7. I was recommended this web site by my cousin. I’m
    not sure whether this post is written by him as no one else
    know such detailed about my problem. You are wonderful!

    Thanks!

  8. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your
    blog and I look forward to your new updates.

  9. Having read this I thought it was very informative. I appreciate you finding the time and
    energy to put this short article together. I once again find myself personally spending a lot of time both reading and posting comments.
    But so what, it was still worthwhile!

  10. hi! may i know is your code complete? because i run the program and does nothing, i have download the given source code.

    • Yes this code is working…You have to create file on php server to store FCM key into your database for future use. First check on your android studio log whether FCM token is printing OR not. If it is printing in log than send token to your web server.

  11. Good day! I could have sworn I’ve been to
    this website before but after going through
    a few of the articles I realized it’s new to me.

    Nonetheless, I’m certainly delighted I found it and I’ll be book-marking it and checking back regularly!

  12. Spot on with this write-up, I absolutely feel this website needs much more attention. I’ll probably be returning to read
    through more, thanks for the info!

  13. Hey very cool website!! Man .. Excellent ..
    Amazing .. I will bookmark your site and take the feeds additionally?
    I am glad to search out numerous useful info here
    in the submit, we need work out more strategies
    on this regard, thanks for sharing. . . . . .

  14. Pingback: ExoPlayer Android Example- Best Alternative of VideoView By Kamal

  15. Pingback: Simplest way to get WordPress Post in Android App- REST API

  16. I just like the helpful information you supply to your articles.

    I’ll bookmark your blog and test once more here frequently.
    I’m fairly sure I will learn many new stuff proper here!
    Good luck for the following!

Comments are closed.