First steps launching the main activity.
authorgumartinm <gu.martinm@gmail.com>
Wed, 14 Dec 2011 03:25:23 +0000 (04:25 +0100)
committergumartinm <gu.martinm@gmail.com>
Wed, 14 Dec 2011 03:25:23 +0000 (04:25 +0100)
CookieManager working smoothly

Android/Testing/Test1/AndroidManifest.xml
Android/Testing/Test1/src/de/android/test1/MobieAdHttpAuthClient.java
Android/Testing/Test1/src/de/android/test1/Test1Activity.java
Android/Testing/Test2/AndroidManifest.xml
Android/Testing/Test2/gen/de/android/test2/R.java
Android/Testing/Test2/res/layout/main.xml
Android/Testing/Test2/src/de/android/test2/Test2Activity.java

index 0907f84..7421260 100644 (file)
         
         <activity 
                        android:label="@string/app_name"
-                       android:name=".NextActivity" >
+                       android:name=".NextActivity" 
+                       android:theme="@android:style/Theme.Black" 
+                       android:screenOrientation="portrait" 
+                       android:configChanges="touchscreen|keyboard" 
+                       android:permission="android.permission.INTERNET">
+            <intent-filter>
+                <action android:name="android.intent.action.RUN"/>
+            </intent-filter>
                </activity>
                
     </application>
index 50bbb55..ab299dd 100644 (file)
@@ -90,8 +90,7 @@ public class MobieAdHttpAuthClient extends AsyncTask<URL, Integer, HttpResponse>
                                        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
index 56a2dde..b8a97d5 100644 (file)
@@ -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) {
index 57577ad..b91a79d 100644 (file)
         
         <activity 
                        android:label="@string/app_name"
-                       android:name=".NextActivity" >
+                       android:name=".NextActivity" 
+                       android:theme="@android:style/Theme.Black" 
+                       android:screenOrientation="portrait" 
+                       android:configChanges="touchscreen|keyboard" 
+                       android:permission="android.permission.INTERNET">
+            <intent-filter>
+                <action android:name="android.intent.action.RUN"/>
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
                </activity>
                
     </application>
index 37ca302..6317ccd 100644 (file)
@@ -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;
index 89a734a..1e03635 100644 (file)
@@ -8,7 +8,8 @@
     
     <FrameLayout 
        android:id="@+id/frameLayout1" 
-       android:layout_width="match_parent" android:layout_height="70dp">
+       android:layout_width="match_parent" 
+       android:layout_height="70dp">
     </FrameLayout>
            
        <EditText
index 72c89a0..b8d4f84 100644 (file)
@@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpPost;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.message.BasicNameValuePair;
 import android.app.Activity;
+import android.content.Intent;
 import android.os.Bundle;
 import android.os.StrictMode;
 import android.util.Log;
@@ -25,6 +26,7 @@ import android.widget.EditText;
 
 public class Test2Activity extends Activity {
        private static final String TAG = "Test2Activity";
+       
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -39,9 +41,8 @@ public class Test2Activity extends Activity {
        final String URLAuth = "http://192.168.1.34/userfront.php/api/login/auth.json";
        final EditText password = (EditText) findViewById(R.id.password);
        final EditText username = (EditText) findViewById(R.id.username);
-
-               HttpClient httpClient = new DefaultHttpClient();
-               HttpPost httpPost = new HttpPost(URLAuth);
+       final HttpClient httpClient = new DefaultHttpClient();
+               final HttpPost httpPost = new HttpPost(URLAuth);
                HttpEntity httpEntity = null;
                HttpResponse httpResponse = null;
                final List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(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) {