Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.goosipe.girl;
- import android.os.AsyncTask;
- import android.util.Log;
- import org.json.JSONObject;
- import java.io.BufferedInputStream;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.ProtocolException;
- import java.net.URL;
- public class MonJson extends AsyncTask {
- private boolean turnon = true;
- private String banner = "";
- private String interstitial = "";
- private String nativeads = "";
- private String startapp = "";
- private String store = "";
- private String usus = "";
- private String update = "";
- @Override
- protected Object doInBackground(Object... params) {
- this.parse();
- return this;
- }
- private void parse()
- {
- Gethttp sh = new Gethttp();
- String url = "https://api.myjson.com/bins/60ui0";
- String jsonStr = sh.makeServiceCall(url);
- try {
- JSONObject jsonRoot = new JSONObject(jsonStr);
- String turnonString = jsonRoot.getString("turnon");
- Log.d("turnonjson : ", turnonString);
- if(turnonString.equals("ON"))
- {
- turnon = true;
- }
- if(turnonString.equals("OFF"))
- {
- turnon = false;
- }
- store = jsonRoot.getString("store");
- banner = jsonRoot.getString("banner");
- interstitial = jsonRoot.getString("interstitial");
- startapp = jsonRoot.getString("startapp");
- nativeads = jsonRoot.getString("native");
- update = jsonRoot.getString("update");
- usus = jsonRoot.getString("usus");
- }
- catch(Exception e)
- {
- }
- }
- public String isUsUs()
- {
- return usus;
- }
- public String isUpdate()
- {
- return update;
- }
- public String isBanner()
- {
- return banner;
- }
- public String isInterstitial()
- {
- return interstitial;
- }
- public String isStartapp()
- {
- return startapp;
- }
- public String isNative()
- {
- return nativeads;
- }
- public boolean isTurnon()
- {
- return turnon;
- }
- public String isStore()
- {
- return store;
- }
- public class Gethttp {
- private final String TAG = Gethttp.class.getSimpleName();
- public Gethttp() {
- }
- public String makeServiceCall(String reqUrl) {
- String response = null;
- try {
- URL url = new URL(reqUrl);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setRequestMethod("GET");
- // read the response
- InputStream in = new BufferedInputStream(conn.getInputStream());
- response = convertStreamToString(in);
- } catch (MalformedURLException e) {
- Log.e(TAG, "MalformedURLException: " + e.getMessage());
- } catch (ProtocolException e) {
- Log.e(TAG, "ProtocolException: " + e.getMessage());
- } catch (IOException e) {
- Log.e(TAG, "IOException: " + e.getMessage());
- } catch (Exception e) {
- Log.e(TAG, "Exception: " + e.getMessage());
- }
- return response;
- }
- private String convertStreamToString(InputStream is) {
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- StringBuilder sb = new StringBuilder();
- String line;
- try {
- while ((line = reader.readLine()) != null) {
- sb.append(line).append('\n');
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement