Testing a SQLite provider.
authorgumartinm <gu.martinm@gmail.com>
Thu, 2 Feb 2012 21:31:07 +0000 (22:31 +0100)
committergumartinm <gu.martinm@gmail.com>
Thu, 2 Feb 2012 21:31:07 +0000 (22:31 +0100)
Android/Testing/Test3/AndroidManifest.xml
Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java [new file with mode: 0644]
Android/Testing/Test3/src/de/android/test3/IndexerProvider.java [new file with mode: 0644]
Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java

index 548eed8..311d2f6 100644 (file)
             </intent-filter>
                </activity>
                
+               <provider 
+                   android:authorities="de.android.test3.provider"
+               android:enabled="true"
+               android:exported="false"
+               android:grantUriPermissions="false"
+               android:icon="@drawable/ic_launcher"
+               android:initOrder="1"
+               android:label="@string/app_name"
+               android:multiprocess="false"
+               android:name=".IndexerProvider"
+               android:permission="android.permission.MOBIADS"
+               android:readPermission="android.permission.READ_MOBIADS"
+               android:syncable="false"
+               android:writePermission="android.permission.WRITE_MOBIADS" >
+            <grant-uri-permission 
+                android:path="string"
+                android:pathPattern="string"
+                android:pathPrefix="string" />
+               </provider>
+               <!--
+               <provider 
+                       android:process="string" When having my service, here I should write the service process name 
+               </provider>-->
+       
     </application>
 
 </manifest>
\ No newline at end of file
diff --git a/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java b/Android/Testing/Test3/src/de/android/test3/IndexerOpenHelper.java
new file mode 100644 (file)
index 0000000..4b6269a
--- /dev/null
@@ -0,0 +1,36 @@
+package de.android.test3;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+public class IndexerOpenHelper extends SQLiteOpenHelper {
+       private static final String DBNAME = "mobiads";
+       private static final int DATABASE_VERSION = 1;
+    private static final String TABLE_NAME = "indexer";
+    private static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME + 
+                                                                                                       "(_ID INTEGER NOT NULL, " +
+                                                                                                       "PATH TEXT(15) NOT NULL, " + 
+                                                                                                       "PRIMARY KEY (_ID), " +
+                                                                                                       "UNIQUE (PATH), " + ")";
+
+    IndexerOpenHelper(Context context) {
+        super(context, DBNAME, null, DATABASE_VERSION);
+    }
+
+
+    /*
+     * Creates the data repository. This is called when the provider attempts to open the
+     * repository and SQLite reports that it doesn't exist.
+     */
+       @Override
+       public void onCreate(SQLiteDatabase db) {
+               db.execSQL(TABLE_CREATE);
+       }
+
+       
+       @Override
+       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+
+       }
+}
diff --git a/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java b/Android/Testing/Test3/src/de/android/test3/IndexerProvider.java
new file mode 100644 (file)
index 0000000..a1142e2
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * 
+ */
+package de.android.test3;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
+
+/**
+ *
+ */
+public class IndexerProvider extends ContentProvider {
+       // Holds the database object
+    private SQLiteDatabase db;
+    /*
+     * Defines a handle to the database helper object. The MainDatabaseHelper class is defined
+     * in a following snippet.
+     */
+    private IndexerOpenHelper mOpenHelper;
+
+       
+       /* (non-Javadoc)
+        * @see android.content.ContentProvider#delete(android.net.Uri, java.lang.String, java.lang.String[])
+        */
+       @Override
+       public int delete(Uri uri, String selection, String[] selectionArgs) {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       /* (non-Javadoc)
+        * @see android.content.ContentProvider#getType(android.net.Uri)
+        */
+       @Override
+       public String getType(Uri uri) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see android.content.ContentProvider#insert(android.net.Uri, android.content.ContentValues)
+        */
+       @Override
+       public Uri insert(Uri uri, ContentValues values) {
+               /*
+         * Gets a writeable database. This will trigger its creation if it doesn't already exist.
+         *
+         */
+        db = mOpenHelper.getWritableDatabase();
+
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see android.content.ContentProvider#onCreate()
+        */
+       @Override
+       public boolean onCreate() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       /* (non-Javadoc)
+        * @see android.content.ContentProvider#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)
+        */
+       @Override
+       public Cursor query(Uri uri, String[] projection, String selection,
+                       String[] selectionArgs, String sortOrder) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see android.content.ContentProvider#update(android.net.Uri, android.content.ContentValues, java.lang.String, java.lang.String[])
+        */
+       @Override
+       public int update(Uri uri, ContentValues values, String selection,
+                       String[] selectionArgs) {
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+}
index 369d809..becd13f 100644 (file)
@@ -89,7 +89,7 @@ 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.
+                                                  //Find out if that id is in the SQLite database.
                                                   downloadAds((Integer) objects.get("id"), (String)objects.get("domain"), (String)objects.get("link"));   
                                           }    
                                   }  
@@ -136,7 +136,7 @@ public class MobieAdHttpClient implements Runnable
                                                   }
                                           } finally {
                                                   //instream will never be null in case of reaching this code, cause it was initialized outside try/catch block.
-                                                  //In case of exception here, it is thrown to the superior layer.
+                                                  //In case of exception here, it is thrown to the upper layer.
                                                   instream.close();    
                                           }                            
                                   }