In the src folder of the project, add a new Java class file and name it (see Figure 7-5).

tenderlaSoftware and s/w Development

Dec 13, 2013 (3 years and 10 months ago)

64 views

1.

In the src folder of the project, add a new Java class file and name it
BooksProvider.java
(see Figure 7
-
5).

'
4

ley CuiitcntPiuviikn

4

flP
arc

4

fli
net. lea rr
\
2dcvclo p. Content Providers BooksProvtderjivj

t*
Q M«nAclivityiflv*

&
i?
4
*
gen
loenerated Java Mcsl t>
at,
Android
23

d
\
vt
\

t>
ft
res

________________________________
___


FIGURE 7
-
5

3

.

Populate the BooksProvider.java file as follows:

package
net.learn2develop.ContentProviders;

import
android.content.ContentProvider;

import
android.content.ContentUris;

import
android.content.ContentValues;

import
android.content.Context;

import
android.content.UriMatcher;

import
android.database.Cursor;

import
android.database.SQLException;

import
android.database.sqlite.SQLiteDatabase;

import
android.database.sqlite.SQLiteOpenHelper;

import
android.database.sqlite.SQLiteQueryBuilder;

import
android.net.Uri;

import
android.text.TextUtils;

import
android.util.Log;

public class
BooksProvider
extends
ContentProvider {

public static final
String
PROVIDER_NAME
=
"net.learn2develop.provider.Books"
;

public static final
Uri
CONTENT_URI
=

Uri.parse(
"content://"
+
PROVIDER_NAME
+
"/books"
);

public static final
String
_ID
=
"_id"
;
public static final
String
TITLE
=
"title"
;
public static final
String
ISBN
=
"isbn"
;

private static final int
BOOKS
= 1;
private static final int
BOOK_ID
= 2;

private static final
UriMatcher
uriMatcher
;
static
{

uriMatcher
=
new
UriMatcher(UriMatcher.
NO_MATCH
);
uriMatcher
.addURI(
PROVIDER_NAME
,
"books"
,
BOOKS
);
uriMatcher
.addU
RI(
PROVIDER_NAME
,
"books/#"
,
BOOK_ID
);

}

//

-------

for database use

------------------


private
SQLiteDatabase
booksDB
;