When I first started creating Android applications, I decided to create a demo application that allowed me to search WebCenter Content in order to find and display content from Fishbowl’s main Content Server.  Since Android applications are written in Java, an easy option was to use Oracle’s Remote Intradoc Client (RIDC) API to create the integration.  Fishbowl has used RIDC to integrate a number of our products with WebCenter Content, including our Intranet In A Box and Enterprise Batchloader products, so I had a solid codebase already to work from.  You can find more info on the RIDC API here.    In this post I will walk through the steps required to get RIDC integrated into an Android application as well as create a connection to the Content Server in order to execute a search and return data.

Start by creating a brand new Android application in Eclipse.  If you have not created an Android app before, Google has some really good tutorials that can be found here.  I named my new application WebCenter Search.

Since this new application will be using the internet connection of the phone to query the Content Server, make sure you add the proper permissions to your AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET" />

Next, download the RIDC client jar file from the Oracle WebCenter Content downloads page here.  The RIDC client jar file needs to be dropped into the libs folder of your Android application in order to use it in your app.  Additionally, RIDC requires the Jakarta Commons Http Client jar file in order to communicate over HTTP with the Content Server.  The Jakarta Commons Http Client jar file will need to be dropped into the libs folder of your Android application as well.  You can find more info on that jar file here.  Once those two jar files are in place, your application is ready to integrate with the Content Server.

In practice you will most likely want to create a login page and store a user’s credentials after successful login, and you may also want to have a way for the user to enter and store the Content Server URL to which they are connecting.  I won’t cover those topics here as there are a ton of examples of login pages and storing user preference data if you do a simple Google search.  I will hardcode that information for simplicity sake.

To create a search interface, start by creating a search input field and a search button in the main activity layout of your application.  The search button will have an onClick function (called doSearch in my case) that will perform the search.  I have also created an extra TextView in my layout to demonstrate displaying the results that come back from a search.  My sample layout XML file looks like this:

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical”>

<EditText

android:id=“@+id/search_field”

android:layout_width=“200dp”

android:layout_height=“50dp” />

<Button

android:layout_width=“wrap_content”

android:layout_height=“50dp”

android:text=“Search”

android:onClick=“doSearch”/>

<TextView

android:id=“@+id/search_results”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”/>

</LinearLayout>

 

Next, initialize the connection to the Content Server in the onCreate method of your main activity by creating IdcClient and IdcContext objects.  The connection will need to be initialized with the CGI path to the Content Server in order to tell RIDC to connect over HTTP instead of over the socket.

public class MainActivity extends Activity {

 

private IdcClient idcClient;

private IdcContext userPasswordContext;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

String contentServerURL = “https://myserver.mydomain.com/cs/idcplg”;

IdcClientManager manager = new IdcClientManager();

try {

this.idcClient = manager.createClient(contentServerURL);

this.userPasswordContext = new IdcContext(“weblogic”, “welcome1”);

} catch (IdcClientException e) {

e.printStackTrace();

}

}

}

Once a connection to the Content Server has been properly initialized, you are ready to implement the doSearch method.  Simply pass the required search parameters into a DataBinder object, and execute the GET_SEARCH_RESULTS service using the IdcClient and IdcContext objects created when initializing the Content Server connection.  The results can then be taken from the ServiceResponse object and displayed in your app.  The example below will take all the Content IDs from the search results that are returned and put them in to a comma separated string to be displayed in the app.  Note that since the doSearch method is making a connection over the network, best practice dictates that this process be run in a separate thread so that you don’t lock the main UI thread while the search is being run.  This is handled in the example below by creating a GetSearchResultsTask class to do most of the work.

public void doSearch(View v) throws IdcClientException  {

GetSearchResultsTask gsrt = new GetSearchResultsTask();

gsrt.execute();

}

 

private class GetSearchResultsTask extends AsyncTask<String, Integer, DataResultSet>{

protected DataResultSet doInBackground(String… queryText)

{

DataResultSet searchResults = null;

try {

EditText searchField = (EditText) findViewById(R.id.search_field);

String searchVal = searchField.getText().toString();

DataBinder binder = idcClient.createBinder();

binder.putLocal(“IdcService”, “GET_SEARCH_RESULTS”);

binder.putLocal(“QueryText”, “dDocType <MATCHES> `” + searchVal + “`”);

ServiceResponse response = idcClient.sendRequest (userPasswordContext, binder);

DataBinder serverBinder = response.getResponseAsBinder();

searchResults = serverBinder.getResultSet(“SearchResults”);

} catch (Exception e) {

e.printStackTrace();

}

return searchResults;

}

protected void onPostExecute(DataResultSet searchResults) {

TextView searchResultsView = (TextView) findViewById(R.id.search_results);

String allContentIDs = “”;

List<DataObject> searchResultsList = searchResults.getRows();

for(DataObject result : searchResultsList)

{

String contentId = result.get(“dDocName”);

if(allContentIDs.length() == 0) {

allContentIDs = contentId;

}

else{

allContentIDs += “,” + contentId;

}

}

searchResultsView.setText(allContentIDs);

}

}

When I run the app and do a search, the results look like this:

There is still a lot of work to be done to make this into a usable app, however these basic steps outline the minimum needed to integrate an Android app with the Content Server without having to write the integration pieces yourself.  The major drawback to this approach of course is that it is Android specific and will not work on iOS devices.  If you’re looking for WebCenter Content apps for both Android and iOS, check out the FishbowlToGo app.  The FishbowlToGo app uses Fishbowl’s proprietary JSON-based mobility API to integrate with the Content Server, and has some pretty cool features and functionality.