• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Accessing the database in another application using the content provider

sriranga

Lurker
Jan 27, 2010
2
0
Hi,

Can any one tell me how to access the database in one application to other while using the content provider.

Table creation was successful and i am able to access the data in that application.
Here i am sending my code snippest for accessing the table in another application.

String columns[] = new String[] {"_id","roll","name"};
Uri myUri = Uri.parse("content://com.example.mytable/table1");

ContentProviderClient cpc = getContentResolver().acquireContentProviderClient(myUri);
Cursor cur=null;
try {

cur = cpc.query(myUri, null, null,null,null);

} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(cur==null){
Toast.makeText(this, "There is no records to Dispaly", Toast.LENGTH_LONG).show();
}
else{
if (cur.moveToFirst()) {
String id = null;
String roll=null;
String userName = null;
do {
id = cur.getString(cur.getColumnIndex(TABLE_ID));
userName = cur.getString(cur.getColumnIndex(TABLE_NAME));
roll=cur.getString(cur.getColumnIndex(TABLE_ROLL));
Toast.makeText(this, id + " " +roll+" "+ userName, Toast.LENGTH_LONG).show();
} while (cur.moveToNext());

i am getting the cur object as null. I gave the permissions to the table in the xml file

permission android:name="com.example.mytable.Permission.WRITE" android:protectionLevel="normal" android:description="@string/hello" />
<permission android:name="com.example.mytable.Permission.READ" android:protectionLevel="normal" android:description="@string/hello" />


so can please suggest me to over come this problem.
 
Hi,

Can any one tell me how to access the database in one application to other while using the content provider.

Table creation was successful and i am able to access the data in that application.
Here i am sending my code snippest for accessing the table in another application.

String columns[] = new String[] {"_id","roll","name"};
Uri myUri = Uri.parse("content://com.example.mytable/table1");

ContentProviderClient cpc = getContentResolver().acquireContentProviderClient(myUri);
Cursor cur=null;
try {

cur = cpc.query(myUri, null, null,null,null);

} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(cur==null){
Toast.makeText(this, "There is no records to Dispaly", Toast.LENGTH_LONG).show();
}
else{
if (cur.moveToFirst()) {
String id = null;
String roll=null;
String userName = null;
do {
id = cur.getString(cur.getColumnIndex(TABLE_ID));
userName = cur.getString(cur.getColumnIndex(TABLE_NAME));
roll=cur.getString(cur.getColumnIndex(TABLE_ROLL));
Toast.makeText(this, id + " " +roll+" "+ userName, Toast.LENGTH_LONG).show();
} while (cur.moveToNext());

i am getting the cur object as null. I gave the permissions to the table in the xml file

permission android:name="com.example.mytable.Permission.WRITE" android:protectionLevel="normal" android:description="@string/hello" />
<permission android:name="com.example.mytable.Permission.READ" android:protectionLevel="normal" android:description="@string/hello" />


so can please suggest me to over come this problem.


Welcome to the AF forums and enjoy your visits !! :cool:

have move this to the developers forum section
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones