Gerard Beaulieu
- Forum posts: 3
Feb 19, 2014, 7:06:46 AM via Website
Feb 19, 2014 7:06:46 AM via Website
Hey all!
New to Android but not developing. App runs great with emulator running Android 2.3.3. When I install the app to my phone (Samsung Galaxy 4S Active) runnnig Android 4.2.2, the Http Get execute command on the client does not seem to happen. I get no data back reported to my TextView.
I know there is some learning curve I'm missing here, and would appreciate some guidance.
HttpExample.java
GetMethodEx.java
AndroidManifest.xml
httpex.xml
I would post the logcat but there really is no issue at 2.3.3... just need to know what i'm missing going to 4.2.2.
Thanks in advance, I know this should be easy for you all.
New to Android but not developing. App runs great with emulator running Android 2.3.3. When I install the app to my phone (Samsung Galaxy 4S Active) runnnig Android 4.2.2, the Http Get execute command on the client does not seem to happen. I get no data back reported to my TextView.
I know there is some learning curve I'm missing here, and would appreciate some guidance.
HttpExample.java
1package com.example.test;
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.widget.TextView;
6
7public class HttpExample extends Activity {
8
9 TextView httpStuff;
10
11 @Override
12 protected void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.httpex);
15 httpStuff = (TextView) findViewById(R.id.tvHttp);
16 GetMethodEx test = new GetMethodEx();
17 try {
18 String returned = test.getInternetData();
19 httpStuff.setText(returned);
20 } catch (Exception e) {
21 // TODO Auto-generated catch block
22 e.printStackTrace();
23 }
24
25
26 }
27
28
29}
2
3import android.app.Activity;
4import android.os.Bundle;
5import android.widget.TextView;
6
7public class HttpExample extends Activity {
8
9 TextView httpStuff;
10
11 @Override
12 protected void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.httpex);
15 httpStuff = (TextView) findViewById(R.id.tvHttp);
16 GetMethodEx test = new GetMethodEx();
17 try {
18 String returned = test.getInternetData();
19 httpStuff.setText(returned);
20 } catch (Exception e) {
21 // TODO Auto-generated catch block
22 e.printStackTrace();
23 }
24
25
26 }
27
28
29}
GetMethodEx.java
1package com.example.test;
2
3import java.io.BufferedReader;
4import java.io.InputStreamReader;
5import java.net.URI;
6
7import org.apache.http.HttpResponse;
8import org.apache.http.client.HttpClient;
9import org.apache.http.client.methods.HttpGet;
10import org.apache.http.impl.client.DefaultHttpClient;
11
12public class GetMethodEx {
13
14 public String getInternetData () throws Exception {
15 BufferedReader in = null;
16 String data = null;
17 try {
18 HttpClient client = new DefaultHttpClient();
19 URI website = new URI("CANTPOSTURL");
20 HttpGet request = new HttpGet();
21 request.setURI(website);
22 HttpResponse response = client.execute(request);
23 in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
24 StringBuffer sb = new StringBuffer("");
25 String l = "";
26 String nl = System.getProperty("line.separator");
27 while ((l = in.readLine()) !=null) {
28 sb.append(l + nl);
29
30 }
31 in.close();
32 data = sb.toString();
33 return data;
34
35 }finally {
36 if (in !=null) {
37 try {
38 in.close();
39 return data;
40 }catch (Exception e) {
41 e.printStackTrace();
42 }
43 }
44 }
45
46
47 }
48
49}
2
3import java.io.BufferedReader;
4import java.io.InputStreamReader;
5import java.net.URI;
6
7import org.apache.http.HttpResponse;
8import org.apache.http.client.HttpClient;
9import org.apache.http.client.methods.HttpGet;
10import org.apache.http.impl.client.DefaultHttpClient;
11
12public class GetMethodEx {
13
14 public String getInternetData () throws Exception {
15 BufferedReader in = null;
16 String data = null;
17 try {
18 HttpClient client = new DefaultHttpClient();
19 URI website = new URI("CANTPOSTURL");
20 HttpGet request = new HttpGet();
21 request.setURI(website);
22 HttpResponse response = client.execute(request);
23 in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
24 StringBuffer sb = new StringBuffer("");
25 String l = "";
26 String nl = System.getProperty("line.separator");
27 while ((l = in.readLine()) !=null) {
28 sb.append(l + nl);
29
30 }
31 in.close();
32 data = sb.toString();
33 return data;
34
35 }finally {
36 if (in !=null) {
37 try {
38 in.close();
39 return data;
40 }catch (Exception e) {
41 e.printStackTrace();
42 }
43 }
44 }
45
46
47 }
48
49}
AndroidManifest.xml
1<?xml version="1.0" encoding="utf-8"?>
2<manifest xmlns:android="CANTPOSTURL"
3 package="com.example.test"
4 android:versionCode="1"
5 android:versionName="1.0" >
6
7 <uses-sdk
8 android:minSdkVersion="8"
9 android:targetSdkVersion="18" />
10
11 <uses-permission android:name="android.permission.INTERNET" />
12 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
13
14 <application
15 android:allowBackup="true"
16 android:icon="@drawable/ic_launcher"
17 android:label="@string/app_name"
18 android:theme="@style/AppTheme" >
19 <activity
20 android:name="com.example.test.HttpExample"
21 android:label="@string/app_name" >
22 <intent-filter>
23 <action android:name="android.intent.action.MAIN" />
24
25 <category android:name="android.intent.category.LAUNCHER" />
26 </intent-filter>
27 </activity>
28 </application>
29
30</manifest>
2<manifest xmlns:android="CANTPOSTURL"
3 package="com.example.test"
4 android:versionCode="1"
5 android:versionName="1.0" >
6
7 <uses-sdk
8 android:minSdkVersion="8"
9 android:targetSdkVersion="18" />
10
11 <uses-permission android:name="android.permission.INTERNET" />
12 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
13
14 <application
15 android:allowBackup="true"
16 android:icon="@drawable/ic_launcher"
17 android:label="@string/app_name"
18 android:theme="@style/AppTheme" >
19 <activity
20 android:name="com.example.test.HttpExample"
21 android:label="@string/app_name" >
22 <intent-filter>
23 <action android:name="android.intent.action.MAIN" />
24
25 <category android:name="android.intent.category.LAUNCHER" />
26 </intent-filter>
27 </activity>
28 </application>
29
30</manifest>
httpex.xml
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="CANTPOSTURL"
3 xmlns:tools="CANTPOSTURL"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 android:orientation="vertical"
7 tools:context=".HttpActivity">
8
9 <ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent">
10
11 <TextView
12 android:id="@+id/tvHttp"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:text="Loading Data" >
16 </TextView>
17 </ScrollView>
18
19</LinearLayout>
2<LinearLayout xmlns:android="CANTPOSTURL"
3 xmlns:tools="CANTPOSTURL"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 android:orientation="vertical"
7 tools:context=".HttpActivity">
8
9 <ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent">
10
11 <TextView
12 android:id="@+id/tvHttp"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:text="Loading Data" >
16 </TextView>
17 </ScrollView>
18
19</LinearLayout>
I would post the logcat but there really is no issue at 2.3.3... just need to know what i'm missing going to 4.2.2.
Thanks in advance, I know this should be easy for you all.
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.