0

I want to show content in webview from the server.The data is coming from server in html form.How I can so it on webview.The data variable contained all the results but i am not able to read the html contents.

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard__description__page);
        WebView webView = (WebView) findViewById(R.id.webview);
        // String summary = "<html><body>You scored <b>192</b> points.</body></html>";
        webView.loadData(summary, "text/html", null);


        if (savedInstanceState == null) {
            Bundle extras = getIntent().getExtras();

            if(extras == null) {
                alternate_id= null;
                bookmarkid= null;
                bookmarkfile = null;
            } else {
                alternate_id= extras.getString("alternateid");
                bookmarkid= extras.getString("bookmarkid");
                bookmarkfile = extras.getString("bookmarkfile");

            }
        } else {
            alternate_id= (String) savedInstanceState.getSerializable("alternateid");
            bookmarkid= (String) savedInstanceState.getSerializable("bookmarkid");
            bookmarkfile= (String) savedInstanceState.getSerializable("bookmarkfile");

        }




        // System.out.println(stringCameFromFirstAcvitity);

      //  actorsList = new ArrayList<Actors>();
        new JSONReaderAsyncTask().execute("https://www.webmod.com/mydata/get_article_detail?", " access_token", "bookmark_file", "alternate_id", "bookmarkId");

        reader_back=(ImageButton)findViewById(R.id.reader_back_btn);
        reader_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent dash_back = new Intent(getApplicationContext(),Dashboard.class);
                startActivity(dash_back);

            }
        });


    }

    class JSONReaderAsyncTask extends AsyncTask<String, Void, Boolean> {

        ProgressDialog dialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog = new ProgressDialog(Dashboard_Description__page.this);
            dialog.setMessage("Loading, please wait");
            dialog.setTitle("Connecting server");
            dialog.show();
            dialog.setCancelable(false);


        }

        @Override
        protected Boolean doInBackground(String... params)
        {
            HttpParams httpParameters = new BasicHttpParams();

            HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);

            HttpConnectionParams.setSoTimeout(httpParameters, 5000);
            HttpClient httpClient = new DefaultHttpClient(httpParameters);

            HttpPost httpPost = new HttpPost(params[0]);
            String jsonResult = "";
            try {

                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);

                nameValuePairs.add(new BasicNameValuePair("access_token", "94529e5dbc6234fc3bbfce7406b8dde9"));
                nameValuePairs.add(new BasicNameValuePair("bookmark_file", bookmarkfile));
                nameValuePairs.add(new BasicNameValuePair("alternate_id", alternate_id));
                nameValuePairs.add(new BasicNameValuePair("bookmarkId", bookmarkid));

               // System.out.println(alternate_id);
                //System.out.println(bookmarkfile);
               // System.out.println(bookmarkid);
                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpClient.execute(httpPost);
                // System.out.println("hello Hitu");

                //  jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
                // System.out.println(jsonResult);
                // StatusLine stat = response.getStatusLine();
                int status = 200;

                if (status == 200) {
                    HttpEntity entity = response.getEntity();
                    String data = EntityUtils.toString(entity);
                  //  ArrayList<String> mylist = new ArrayList<String>();
                   // mylist.add(data);
                   // System.out.println(first);


                    System.out.println(data);
                    System.out.println("fffff");
                    JSONObject jsono = new JSONObject(data);
                    JSONArray jarray = jsono.getJSONArray("content");

                    }
                    return true;


                //------------------>>

            } catch (ParseException e1) {
                e1.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return false;
        }

        protected void onPostExecute(Boolean result) {
            dialog.cancel();
           // adapter.notifyDataSetChanged();
            if(result == false)
                Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();

        }

    }

}
pawan kumar
  • 61
  • 10

1 Answers1

1

Okey. as you stated you want those data to be desplayed in WebView this is what you can do.

wv = (WebView) findViewById(R.id.webView)
wv.loadDataWithBaseURL("", YOUR_TEXT, "text/html", "utf-8", "");

I hope this will help.

V-rund Puro-hit
  • 5,270
  • 8
  • 27
  • 48