Having fun with my provider. It does not work yet...
authorgumartinm <gu.martinm@gmail.com>
Fri, 10 Feb 2012 07:00:10 +0000 (08:00 +0100)
committergumartinm <gu.martinm@gmail.com>
Fri, 10 Feb 2012 07:00:10 +0000 (08:00 +0100)
Working with Intents is difficult...

Android/Testing/Test3/res/values/strings.xml
Android/Testing/Test3/src/de/android/test3/IndexerProvider.java
Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java
Android/Testing/Test3/src/de/android/test3/Test3Activity.java

index 21bf57c..2c02d74 100644 (file)
@@ -4,7 +4,7 @@
         Do you really want to close the application?
     </string>
     <string name="error_dialog_connection_error">
-        Connection error with MobAd server.
+        Connection error with MobiAd server.
     </string>
     <string name="error_dialog_userpwd_error">
         The username or password you entered is incorrect.
@@ -16,4 +16,4 @@
     <string name="button_login">Log In</string>
     <string name="button_ok">OK</string>
     <string name="button_cancel">Cancel</string>
-</resources>
\ No newline at end of file
+</resources>
index 3f456f3..aa6cff2 100644 (file)
@@ -41,11 +41,11 @@ public class IndexerProvider extends ContentProvider {
         // Create a new instance
         sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
         
-        // Add a pattern that routes URIs terminated with "notes" to a NOTES operation
+        // Add a pattern that routes URIs terminated with "indexer" to a INDEXER operation
         sUriMatcher.addURI("de.android.test3.provider", Indexer.Index.TABLE_NAME, INDEXER);
         
-        // Add a pattern that routes URIs terminated with "notes" plus an integer
-        // to a note ID operation
+        // Add a pattern that routes URIs terminated with "indexer" plus an integer
+        // to a index ID operation
         sUriMatcher.addURI("de.android.test3.provider", Indexer.Index.TABLE_NAME + "/#", INDEXER_ID);
     }
  
index 9055d26..fe94fe6 100644 (file)
@@ -21,6 +21,8 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.json.JSONTokener;
+import android.content.ContentUris;
+import android.net.Uri;
 import android.net.http.AndroidHttpClient;
 import android.util.Log;
 
@@ -88,7 +90,12 @@ public class MobieAdHttpClient implements Runnable
                                   JSONArray finalResult = new JSONArray(tokener);
                                   for (int i = 0; i < finalResult.length(); i++) {
                                           JSONObject objects = finalResult.getJSONObject(i);
-                                          //Find out if that id is in the SQLite database.
+                                          IndexerProvider databaseIndexer = new IndexerProvider();
+                                          Uri.Builder prueba = new Uri.Builder();
+                                          prueba.encodedAuthority("de.android.test3.provider");
+                                          prueba.encodedPath("indexer");
+                                          prueba.appendQueryParameter("id", (String) objects.get("id"));
+                                          databaseIndexer.query(prueba.build(), null, null, null, null);
                                           downloadAds((Integer) objects.get("id"), (String)objects.get("domain"), (String)objects.get("link"));   
                                   }    
                           } catch (URISyntaxException e) {
index c1be5c4..32ca947 100644 (file)
@@ -21,6 +21,7 @@ import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
+import android.content.ComponentName;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
@@ -89,9 +90,11 @@ public class Test3Activity extends Activity {
                                        CookieSyncManager.getInstance().sync();
                                        //Go to the next activity
                                        StrictMode.setThreadPolicy(currentPolicy);
-                                       this.startActivity(new Intent(Intent.ACTION_RUN));
+                                       this.startActivity(new Intent(Intent.ACTION_RUN).
+                                                       setComponent(new ComponentName("de.android.test3", "de.android.test3.NextActivity")));
                        } else {
                                Log.e(TAG, "There must be a weird issue with the server because... There is not cookie!!!!");
+                               createErrorDialog(R.string.error_dialog_connection_error);
                        }
                                break;
                        case HttpStatus.SC_UNAUTHORIZED:
@@ -104,12 +107,13 @@ public class Test3Activity extends Activity {
                                break;
                        default:
                                Log.e(TAG, "Error while retrieving the HTTP status line.");
-                               createErrorDialog(R.string.error_dialog_userpwd_error);
+                               createErrorDialog(R.string.error_dialog_connection_error);
                                break;
             }          
         } 
         else {
                Log.e(TAG, "No response? This should never have happened.");
+               createErrorDialog(R.string.error_dialog_connection_error);
         }
     }