2

i need to know the changes needed to be made in the manifest file and what permissions are required to make this app run and also my intention is to get the strings from a web page and to display it inside "onPostExecute()"

package com.example.guru;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

import android.os.AsyncTask;
import android.util.Log;

//new code


class RequestTask extends AsyncTask<String, String, String>{

@Override
// username, password, message, mobile
protected String doInBackground(String... url) {
    // constants
    int timeoutSocket = 5000;
    int timeoutConnection = 5000;

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    HttpClient client = new DefaultHttpClient(httpParameters);

    HttpGet httpget = new HttpGet(url[0]);

    try {
        HttpResponse getResponse = client.execute(httpget);
        final int statusCode = getResponse.getStatusLine().getStatusCode();

        if(statusCode != HttpStatus.SC_OK) {
            Log.w("MyApp", "Download Error: " + statusCode + "| for URL: " + url);
            return null;
        }

        String line = "";
        StringBuilder total = new StringBuilder();

        HttpEntity getResponseEntity = getResponse.getEntity();

        BufferedReader reader = new BufferedReader(new InputStreamReader(getResponseEntity.getContent()));  

        while((line = reader.readLine()) != null) {
            total.append(line);
        }

        line = total.toString();
        return line;
    } catch (Exception e) {
        Log.w("MyApp", "Download Exception : " + e.toString());
    }
    return null;
}

@Override
protected void onPostExecute(String result) {
    // do something with result

    System.out.println(result);


}
}


//new code end
Akash
  • 220
  • 3
  • 12

2 Answers2

1

You need to add

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Permission to you manifest file

After

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.photon.filnobep"
    android:installLocation="auto"
    android:versionCode="400"
    android:versionName="4.0.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Or add from GUI

enter image description here

Update :1

Add this to your layouts xml file

<TextView
        android:id="@+id/textViewLike"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"           
        android:gravity="center"
        android:maxLines="1"
        android:textColor="#FFF"
        android:textSize="7pt" />

and the following in your activity class

Create a global variable

TextView textVw = null;

Do this in onCreateView

textVw = (TextView) findViewById(R.id.textViewLike);

then this

@Override
protected void onPostExecute(String result) {
    // do something with result


     textVw.setText(result);

}
Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
0
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"

 />
Technivorous
  • 1,682
  • 2
  • 16
  • 22