From 9d4192968522436e485cd8772c322822e042effd Mon Sep 17 00:00:00 2001 From: gumartinm Date: Fri, 10 Feb 2012 08:00:10 +0100 Subject: [PATCH] Having fun with my provider. It does not work yet... Working with Intents is difficult... --- Android/Testing/Test3/res/values/strings.xml | 4 ++-- Android/Testing/Test3/src/de/android/test3/IndexerProvider.java | 6 +++--- .../Testing/Test3/src/de/android/test3/MobieAdHttpClient.java | 9 ++++++++- Android/Testing/Test3/src/de/android/test3/Test3Activity.java | 8 ++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Android/Testing/Test3/res/values/strings.xml b/Android/Testing/Test3/res/values/strings.xml index 21bf57c..2c02d74 100644 --- a/Android/Testing/Test3/res/values/strings.xml +++ b/Android/Testing/Test3/res/values/strings.xml @@ -4,7 +4,7 @@ Do you really want to close the application? - Connection error with MobAd server. + Connection error with MobiAd server. The username or password you entered is incorrect. @@ -16,4 +16,4 @@ Log In OK Cancel - \ No newline at end of file + diff --git a/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java b/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java index 3f456f3..aa6cff2 100644 --- a/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java +++ b/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java @@ -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); } diff --git a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java index 9055d26..fe94fe6 100644 --- a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java +++ b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java @@ -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) { diff --git a/Android/Testing/Test3/src/de/android/test3/Test3Activity.java b/Android/Testing/Test3/src/de/android/test3/Test3Activity.java index c1be5c4..32ca947 100644 --- a/Android/Testing/Test3/src/de/android/test3/Test3Activity.java +++ b/Android/Testing/Test3/src/de/android/test3/Test3Activity.java @@ -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); } } -- 2.1.4