From 819c6645113647d30bc8f50ae7deee6bc27db817 Mon Sep 17 00:00:00 2001 From: gumartinm Date: Wed, 14 Dec 2011 04:25:23 +0100 Subject: [PATCH] First steps launching the main activity. CookieManager working smoothly --- Android/Testing/Test1/AndroidManifest.xml | 9 +++++++- .../de/android/test1/MobieAdHttpAuthClient.java | 3 +-- .../Test1/src/de/android/test1/Test1Activity.java | 22 ++++++------------- Android/Testing/Test2/AndroidManifest.xml | 10 ++++++++- Android/Testing/Test2/gen/de/android/test2/R.java | 1 + Android/Testing/Test2/res/layout/main.xml | 3 ++- .../Test2/src/de/android/test2/Test2Activity.java | 25 +++++++++++----------- 7 files changed, 39 insertions(+), 34 deletions(-) diff --git a/Android/Testing/Test1/AndroidManifest.xml b/Android/Testing/Test1/AndroidManifest.xml index 0907f84..7421260 100644 --- a/Android/Testing/Test1/AndroidManifest.xml +++ b/Android/Testing/Test1/AndroidManifest.xml @@ -26,7 +26,14 @@ + android:name=".NextActivity" + android:theme="@android:style/Theme.Black" + android:screenOrientation="portrait" + android:configChanges="touchscreen|keyboard" + android:permission="android.permission.INTERNET"> + + + diff --git a/Android/Testing/Test1/src/de/android/test1/MobieAdHttpAuthClient.java b/Android/Testing/Test1/src/de/android/test1/MobieAdHttpAuthClient.java index 50bbb55..ab299dd 100644 --- a/Android/Testing/Test1/src/de/android/test1/MobieAdHttpAuthClient.java +++ b/Android/Testing/Test1/src/de/android/test1/MobieAdHttpAuthClient.java @@ -90,8 +90,7 @@ public class MobieAdHttpAuthClient extends AsyncTask CookieManager.getInstance().setCookie("192.168.1.34/userfront.php",cookie); CookieSyncManager.getInstance().sync(); //OK GO TO THE NEXT ACTIVITY - Intent i = new Intent(this.context, NextActivity.class); - this.context.startActivity(i); + this.context.startActivity(new Intent(Intent.ACTION_RUN)); break; case HttpStatus.SC_UNAUTHORIZED: //ERROR IN USERNAME OR PASSWORD diff --git a/Android/Testing/Test1/src/de/android/test1/Test1Activity.java b/Android/Testing/Test1/src/de/android/test1/Test1Activity.java index 56a2dde..b8a97d5 100644 --- a/Android/Testing/Test1/src/de/android/test1/Test1Activity.java +++ b/Android/Testing/Test1/src/de/android/test1/Test1Activity.java @@ -1,33 +1,23 @@ package de.android.test1; -import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; -import java.net.URISyntaxException; import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import org.apache.http.HttpEntity; +import java.util.concurrent.ExecutionException; + import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.NameValuePair; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.message.BasicNameValuePair; + import android.app.Activity; import android.content.Intent; -import android.net.http.AndroidHttpClient; import android.os.AsyncTask; +import android.os.AsyncTask.Status; import android.os.Bundle; import android.util.Log; import android.view.View; -import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.widget.EditText; public class Test1Activity extends Activity { - + private static final String TAG = "Test1Activity"; /** Called when the activity is first created. */ @Override @@ -55,7 +45,7 @@ public class Test1Activity extends Activity { // TODO Auto-generated catch block e.printStackTrace(); } - new MobieAdHttpAuthClient(username.getText().toString(), password.getText().toString(), this).execute(url); + new MobieAdHttpAuthClient(username.getText().toString(), password.getText().toString(), this).execute(url); } public void onClickCancel(View v) { diff --git a/Android/Testing/Test2/AndroidManifest.xml b/Android/Testing/Test2/AndroidManifest.xml index 57577ad..b91a79d 100644 --- a/Android/Testing/Test2/AndroidManifest.xml +++ b/Android/Testing/Test2/AndroidManifest.xml @@ -26,7 +26,15 @@ + android:name=".NextActivity" + android:theme="@android:style/Theme.Black" + android:screenOrientation="portrait" + android:configChanges="touchscreen|keyboard" + android:permission="android.permission.INTERNET"> + + + + diff --git a/Android/Testing/Test2/gen/de/android/test2/R.java b/Android/Testing/Test2/gen/de/android/test2/R.java index 37ca302..6317ccd 100644 --- a/Android/Testing/Test2/gen/de/android/test2/R.java +++ b/Android/Testing/Test2/gen/de/android/test2/R.java @@ -23,6 +23,7 @@ public final class R { } public static final class layout { public static final int main=0x7f030000; + public static final int main2=0x7f030001; } public static final class string { public static final int app_name=0x7f040001; diff --git a/Android/Testing/Test2/res/layout/main.xml b/Android/Testing/Test2/res/layout/main.xml index 89a734a..1e03635 100644 --- a/Android/Testing/Test2/res/layout/main.xml +++ b/Android/Testing/Test2/res/layout/main.xml @@ -8,7 +8,8 @@ + android:layout_width="match_parent" + android:layout_height="70dp"> nameValuePairs = new ArrayList(2); @@ -52,17 +53,17 @@ public class Test2Activity extends Activity { try { httpEntity = new UrlEncodedFormEntity(nameValuePairs); } catch (UnsupportedEncodingException e) { - Log.e(TAG, "Error while encoding POST parameters." + e); + Log.e(TAG, "Error while encoding POST parameters.", e); } httpPost.setEntity(httpEntity); httpPost.setHeader("User-Agent", "MobieAds/1.0"); try { httpResponse = httpClient.execute(httpPost); - } catch (ClientProtocolException e1) { - Log.e(TAG, "Error while executing HTTP client connection."); - } catch (IOException e1) { - Log.e(TAG, "Error while executing HTTP client connection."); + } catch (ClientProtocolException e) { + Log.e(TAG, "Error while executing HTTP client connection.", e); + } catch (IOException e) { + Log.e(TAG, "Error while executing HTTP client connection.", e); } if (httpResponse != null) @@ -72,7 +73,8 @@ public class Test2Activity extends Activity { String cookie = httpResponse.getLastHeader("Set-Cookie").getValue(); CookieManager.getInstance().setCookie("192.168.1.34/userfront.php",cookie); CookieSyncManager.getInstance().sync(); - //OK GO TO THE NEXT ACTIVITY + //OK GO TO THE MAIN ACTIVITY + this.startActivity(new Intent(Intent.ACTION_RUN)); break; case HttpStatus.SC_UNAUTHORIZED: //ERROR IN USERNAME OR PASSWORD @@ -84,10 +86,7 @@ public class Test2Activity extends Activity { Log.e(TAG, "Error while retrieving the HTTP status line."); break; } - } - String myCookie = CookieManager.getInstance().getCookie("192.168.1.34/userfront.php"); - Log.e("hola", "Error while retrieving the HTTP status line." + myCookie); - + } } public void onClickCancel(View v) { -- 2.1.4