Sharing CommCare data between apps

29 views
Skip to first unread message

Faizel Faker

unread,
Nov 23, 2017, 2:11:55 AM11/23/17
to commcare-users
Hi Guys,

I am attempting to create an Android mobile application that can be used to generate and display graphs and charts from CommCare application data stored on the mobile device.

I am trying to query a CommCare app data repository by using an Android ContentResolver.

Here is the code I have written to query the database:



-------------------------------
private static final String REPORT_INSTANCE_ID = "commcare:reports";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

try {
selectFixture(REPORT_INSTANCE_ID);
} catch (Exception e) {
e.printStackTrace();
}
}

private void selectFixture(String fixtureId) throws Exception {

String reportXml = getReportXml(fixtureId);
Document document = getXmlDom(reportXml);
renderDocumentToGraph(document);
}

private String getReportXml(String fixtureId) {
ContentResolver cr = getContentResolver();

Cursor c = cr.query(Uri.parse("content://org.commcare.dalvik.case/fixturedb/" + fixtureId), null, null, null, null);
if (!c.moveToFirst()) {
return null;
}
return c.getString(c.getColumnIndex("content"));
}

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



I am not certain if the Uri I am using is correct but the Uri was recommended by a Dimagi employee. However, the ContentResolver always returns NULL when I perform a query.

Can anyone advise me on what I am doing wrong or assist me in resolving this issue.

Thank you

Faizel

Clayton Sims

unread,
Nov 28, 2017, 3:02:54 PM11/28/17
to commcare-users
Hi Faizel,

According to the wiki at


The fixture data content provider root is

content://org.commcare.dalvik.fixture/fixturedb/

not

content://org.commcare.dalvik.case/fixturedb/

Can you try that and see if it addresses the issue?

-Clayton

--
You received this message because you are subscribed to the Google Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages