question: public void doGetJson ( HttpServletRequest request , HttpServletResponse response , String type , String location , String id ) throws ServletException , IOException { response . setContentType ( "application/json; charset=utf-8" ) ; PrintWriter writer = response . getWriter ( ) ; if ( id != null ) { } else { String tmp = request . getParameter ( __PG_START_PARAM ) ; int pgStart = ( tmp == null ? - 1 : Integer . parseInt ( tmp . trim ( ) ) ) ; tmp = request . getParameter ( __PG_SIZE_PARAM ) ; int pgSize = ( tmp == null ? - 1 : Integer . parseInt ( tmp . trim ( ) ) ) ; Uri mediaUri = MediaType . getContentUriByType ( type , location ) ; StringBuilder builder = new StringBuilder ( ) ; MediaCollection collection = null ; writer . println ( "{" ) ; try { collection = new MediaCollection ( resolver . query ( mediaUri , null , null , null , MediaStore . MediaColumns . TITLE + " ASC" ) , pgStart , pgSize ) ; writer . println ( "\"total\": " + collection . getTotal ( ) + ", " ) ; writer . println ( "\"media\": " ) ; writer . print ( "[ " ) ; ContentValues media = null ; int count = pgSize ; while ( ( pgSize <= 0 || count -- > 0 ) && ( media = collection . next ( ) ) != null ) { builder . setLength ( 0 ) ; toJson ( media , mediaUri , builder , type , location ) ; Log . d ( TAG , builder . toString ( ) ) ; writer . print ( builder . toString ( ) ) ; if ( collection . hasNext ( ) ) { writer . print ( "," ) ; } } writer . print ( " ]" ) ; } finally { writer . println ( "}" ) ; collection . close ( ) ; } } }
target:  A request from the Javascript asking for some JSON describing the type of media being requested.