Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Easy way to create android app for your WordPress blog

How to Convert a WordPress Blog into an Android app

     Are you wondering how to create an android blog app for your WordPress site? And are you tired of using some online app generator which has not given any satisfying result as per your expectation? Well, here’s how you can create your own native android app.  Android has given a lot of features to do it on your own way. All you need to know is simple coding knowledge for few features and how to implement them.

     Now, to proceed further you have to know the concept of JSON in android because the process completely depends on  JSONJSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy to read and write and also it is easy for machines to parse and generate. I specifically used Json to make my life easier. Let me explain the process in step by step so that you can easily understand what I did.

Step 1: Login to your WordPress blog, on the left side panel, go to the plugin menu –> click Add new option and search for JSON API. You will be displayed with some number of suggestions. The one we need is the plugin created by Dan Phiffer. Click install now and activate, Now you are good to go.

Step 2: Now go to settings and select the JSON API. You will see the API page with some core, response, and post API’s.

Step 3: Select the one you want and it will automatically generate your blog data into JSON format.

The above image shows the JSON structure of the blog. The [ ] square bracket indicates the JSON array and {} curly bracket indicates the JSON objects. If you have noticed, some of the API don’t work by just clicking them because you have to pass some parameters in the URL in order to make them work.

For example:

“http://www.123.com/api/get_category_posts/”  

This is the normal URL which you will get by clicking the order by category. All you have to do is to tell how you want the categories.

Like, “http://www.123.com/api/get_category_posts/?slug=bikes”

where slug represents one of the JSON objects and bikes is the value of that object.

Note: If you don’t know what is JSON object and array just learn it, because it is necessary for this project.

So, now the WordPress part is completed. Next all we have to do is to create our android project and parse the JSON objects to fetch the values of the blog and display them.

Step 4: Create a new project in Android Studio by clicking File –> New Project and fill out the required details.

Then you have to provide internet permission in your manifest file.

 android:name=”android.permission.INTERNET” />

because JSON fetches data by making Http calls so it requires internet permission.

Step 5:  Parsing JSON in your project.

String url = "your url goes here"

OkHttpClient client = new OkHttpClient();
Request.Builder builder = new Request.Builder();
Request request = builder.url(url).build();

Response response = client.newCall(request).execute();

String json = response.body().string();
JSONObject object = new JSONObject(json);
JSONArray array = object.getJSONArray("posts");

In the above code, JSON data is fetched using HttpClient by making the request and getting the response. The response is then stored in the string (json) variable.

Using that string variable JSON object is created. Now from that object, we can easily fetch the array of posts from our JSON data. That’s it now you can store that data in a string and display them in any textView or in the logs to make sure that everything works fine.

titleTextView=object.optString("title").toString();

where titleTextView is the textView where our data will be displayed and the “title” in double quotes is the JSON object present in JSON array “post“.

That’s it you are good to go now. This is one of the simplest way to get your WordPress blog data in JSON and use them for your app.



This post first appeared on Kinds Of Web Design And Development Services, please read the originial post: here

Share the post

Easy way to create android app for your WordPress blog

×

Subscribe to Kinds Of Web Design And Development Services

Get updates delivered right to your inbox!

Thank you for your subscription

×