Sharing CommCare data between apps

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

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

··· On Thu, Nov 23, 2017 at 2:11 AM, Faizel Faker wrote:

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


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.