I would suggest starting with something like the note pad example in the
SDK, and modifying its content provider to suite your needs.

On Wed, Nov 19, 2008 at 7:48 PM, yasmin afrose <[EMAIL PROTECTED]>wrote:

> Hi Casey,
>
> Thanks for your reply.
>
> I've tried the concept. I got one issue as "Source not found".
>
> My coding are as follows:
> ==================
>
> *DataProvider.java*
> ============
>
> package com.aspire.android.owncontentprovider;
>
> import android.content.ContentProvider;
> import android.content.ContentValues;
> import android.content.Context;
> import android.database.Cursor;
> import android.database.SQLException;
> import android.database.sqlite.SQLiteDatabase;
> import android.database.sqlite.SQLiteOpenHelper;
> import android.net.Uri;
> import android.util.Log;
> public class DataProvider extends ContentProvider {
>      private static final String DATABASE_NAME="bus.db";
>      private static final int DATABASE_VERSION=2;
>      private static final String STATION_TABLE_NAME="station";
>
>      private static class DatabaseHelper extends
> SQLiteOpenHelper{
>            DatabaseHelper(Context context) {
>                super(context, DATABASE_NAME, null, DATABASE_VERSION);
>                // TODO Auto-generated constructor stub
>           }
>           @Override
>           public void onCreate(SQLiteDatabase db) {
>                // TODO Auto-generated method stub
>                db.execSQL("CREATE TABLE "+STATION_TABLE_NAME+"(" + "s_id" +
> "TEXT, "+" s_name "+" TEXT " + ");");
>                String sql_1="insert into
> "+STATION_TABLE_NAME+"(s_id,s_name) values('1','hcz');";
>                String sql_2="insert into
> "+STATION_TABLE_NAME+"(s_id,s_name) values('2','lsdx');";
>                String sql_3="insert into
> "+STATION_TABLE_NAME+"(s_id,s_name) values('3','xal');";
>                try {
>                     db.execSQL(sql_1);
>                     db.execSQL(sql_2);
>                     db.execSQL(sql_3);
>                } catch (SQLException e) {
>                     Log.e("ERROR",e.toString());
>
>                }
>           }
>           @Override
>           public void onUpgrade(SQLiteDatabase db, int oldVersion, int
> newVersion) {
>            Log.w("Data Provider Application : ", "Upgrading database from
> version " + oldVersion + " to "
>                       + newVersion + ", which will destroy all old data");
>               db.execSQL("DROP TABLE IF EXISTS notes");
>               onCreate(db);
>           }
>      }
>      private DatabaseHelper mOpenHelper;
>      @Override
>      public int delete(Uri uri, String selection, String[] selectionArgs) {
>
>           // TODO Auto-generated method stub
>           return 0;
>      }
>      @Override
>      public String getType(Uri uri) {
>           // TODO Auto-generated method stub
>           return null;
>      }
>      @Override
>      public Uri insert(Uri uri, ContentValues values) {
>           // TODO Auto-generated method stub
>           return uri;
>      }
>      @Override
>      public boolean onCreate() {
>           // TODO Auto-generated method stub
>           mOpenHelper = new DatabaseHelper(getContext());
>         return true;
>      }
>      @Override
>      public Cursor query(Uri uri, String[] projection, String selection,
>                String[] selectionArgs, String sortOrder) {
>           // Get the database and run the query
>           SQLiteDatabase db = mOpenHelper.getReadableDatabase();
>           Cursor c = db.query(STATION_TABLE_NAME,projection,
> null,null,null,null,null);
>           return c;
>      }
>      @Override
>      public int update(Uri uri, ContentValues values, String selection,
>                String[] selectionArgs) {
>           // TODO Auto-generated method stub
>           return 0;
>      }
>
> }
>
> *Data.java*
> =======
>
> *
>
> package
> * com.aspire.android.owncontentprovider;
>
>
> *
>
> import
> * java.util.ArrayList;*
>
> import
> * java.util.HashMap;*
>
> import
> * java.util.Map;
>
> *
>
> import
> * android.app.ListActivity;*
>
> import
> * android.content.Intent;*
>
> import
> * android.database.Cursor;*
>
> import
> * android.net.Uri;*
>
> import
> * android.os.Bundle;*
>
> import
> * android.view.View;*
>
> import
> * android.widget.ListView;*
>
> import
> * android.widget.SimpleAdapter;
>
> *
>
> public
> * *class* Data *extends* ListActivity {
>
> *public* *static* *final* String *AUTHORITY*=
> "com.aspire.android.owncontentprovider.dataprovider";
>
> *public* *static* *final* Uri *CONTENT_URI*=Uri.*parse*("content://"+*
> AUTHORITY*+"/station");
>
> *private* *static* *final* String [] *PROJECTION*=*new* String []{
>
> "s_id","s_name"};
>
> // private static final String [] PROJECTION=new String []{"title","body"};
>
>
> @Override
>
> *protected* *void* onCreate(Bundle savedInstanceState) {
>
> *super*.onCreate(savedInstanceState);
>
> //Return the intent that started this activity.
>
> Intent intent=getIntent();
>
> *if*(intent.getData()==*null*)
>
> intent.setData(
> *CONTENT_URI*);
>
> Cursor cur=getContentResolver().query(getIntent().getData(),
> *PROJECTION*,*null*,*null*,*null*);
>
> //int rows = cur.getCount();
>
> // Log.i("No of Rows : ", "");
>
> ArrayList<Map<String,Object>> coll =
> *new* ArrayList<Map<String,Object>>();
>
> Map<String,Object>item;
>
> cur.moveToFirst();
>
> *while*(!cur.isAfterLast()){
>
> item=
> *new* HashMap<String, Object>();
>
> item.put(
> "c1",cur.getString(1)+","+cur.getString(2));
>
> coll.add(item);
>
> cur.moveToNext();
>
> }
>
> *this*.setListAdapter(*new* SimpleAdapter(*this*,coll,android.R.layout.*
> simple_list_item_1*,*new* String[]{"c1"},*new* *int*[]{
>
> android.R.id.
> *text1*}));
>
> }
>
> @Override
>
> *protected* *void* onListItemClick(ListView l, View v, *int* position, *
> long* id) {
>
> // super.onListItemClick(l, v, position, id);
>
> finish();
>
> }
>
> }
> *AndroidManifest.java*
>
> **
>
> <?
> xml version="1.0" encoding="utf-8"?>
>
> <
> manifest xmlns:android="http://schemas.android.com/apk/res/android";
>
> package="com.aspire.android.owncontentprovider"
>
> android:versionCode="1"
>
> android:versionName="1.0.0">
>
> <uses-permission android:name="android.permission.READ_CONTACTS" />
>
> <uses-permission android:name="android.permission.CALL_PHONE" />
>
> <application android:icon="@drawable/icon" android:label=
> "@string/app_name">
>
> <!-- <activity android:name=".Contacts" android:label="@string/app_name">
>
> <intent-filter>
>
> <action android:name="android.intent.action.MAIN" />
>
> <category android:name="android.intent.category.LAUNCHER" />
>
> </intent-filter>* (Accessing the existing Content Provider)*
>
> </activity> -->
>
> <activity android:name=".Data"
>
> android:label="@string/app_name">
>
> <intent-filter>
>
> <action android:name="android.intent.action.MAIN" />
>
> <category
>
> android:name="android.intent.category.LAUNCHER" />
>
> </intent-filter>
>
> </activity>
>
> <provider android:name="DataProvider"
>
> android:authorities="com.aspire.android.owncontentprovider.dataprovider">
>
> </provider>
>
> </application>
>
> </
> manifest>
>
> these are my code, I've attached my application directory structure.
>
> I got error in Data.java(See the file to get the error line) as "Source not
> found". ie, cur = null.
>
> . I've referred the following documentation
>
> http://code.google.com/android/devel/data/contentproviders.html
>
> I want to know in which place the* bus.db* & table(*station*) were
> created. Since, If we give the *authority* in *Manifest* & *Data.jave*file 
> then we are able to get the output.
>
> Please help me... I've tried many ways but I can't get...
>
> But I'm able to access the bulit-in content provider (Eg:
> content://contacts/people).
>
> Thanks for your time ...
>
> Thanks again!!
> Yasmin
>
>
>
>
> On Wed, Nov 19, 2008 at 7:29 PM, Casey Link <[EMAIL PROTECTED]>wrote:
>
>>
>> This isn't how a public forum for developer communication works.
>>
>> You post a specific problem, demonstrate the solutions you have tried,
>> then ask for help. If you want something done entirely for you, put
>> out an advertisement to hire someone that will work for money.
>>
>> Also, I suggest googling "content provider android"
>>
>> Good luck,
>> Casey
>>
>> On Wed, Nov 19, 2008 at 5:19 AM, yasmin afrose <[EMAIL PROTECTED]>
>> wrote:
>> > Hi,
>> >
>> > No body is there aa...
>> >
>> > Please help me to create content provider for our application...
>> >
>> > I can't wait for your answers :(
>> >
>> > Thanks for your time...
>> >
>> >
>> > On Wed, Nov 19, 2008 at 2:36 PM, yasmin afrose <[EMAIL PROTECTED]>
>> > wrote:
>> >>
>> >> Hi,
>> >>
>> >> Anybody knows Content Provider concept in Android.
>> >>
>> >> Please reply me..
>> >>
>> >> Thanks in advance!!!
>> >> Yasmin
>> >> --
>> >> Everything is Possible For U only
>> >
>> >
>> >
>> > --
>> > Everything is Possible For U only
>> >
>> > >
>> >
>>
>> >>
>>


-- 
Dianne Hackborn
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to