Getting conversations

Let's start by adding an endpoint to get all of the conversations on the phone, as follows:

    @GET 
    @Path("conversations") 
    public Response getConversations() { 
      List<Conversation> conversations = new ArrayList<>(); 
      Cursor cur = getApplication().getContentResolver() 
      .query(Telephony.Sms.Conversations.CONTENT_URI,  
      null, null, null, null); 
      while (cur.moveToNext()) { 
        conversations.add(buildConversation(cur)); 
      } 
 
      Collections.sort(conversations, new ConversationComparator()); 
 
      return Response.ok(new GenericEntity<List<Conversation>>( 
      conversations) {}).build(); 
     } 

Here is where we see the Android artifacts start to show up--we are going to use a ContentProvider to access the SMS data. A ContentProvider is a way for an application, ...

Get Java 9 Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.