Super Apps Series (Java): How to leverage pattern recognition in your application (Part 1)


Have you ever noticed how certain strings are underlined in native BlackBerry® smartphone applications? For instance, if you select a phone number that’s underlined or highlighted when reading a message, it is assigned a context-sensitive menu item. Wouldn’t it be great if your application took advantage of this functionality to launch a custom application, open the BlackBerry® Browser to a specific URL, send a message, or perform a number of other actions that provide an integrated user experience?

Good news! As a developer, you have the opportunity to leverage string pattern matching in your BlackBerry applications – which in turn provides a great element of a Super App experience. Starting in handheld 4.3, we introduced a PatternRepository API which allows you to programmatically add custom context-sensitive menu items to standard BlackBerry smartphone applications, based on the matching of text in active text fields with string patterns.

BlackBerry API package for pattern recognition:

Note: Prior to 4.3, this net.rim.device.api.util.StringPattern API was introduced in BlackBerry® Device Software 4.0 and requires you to implement your own string matching algorithm.

Possible use cases for pattern matching would include:

  • Providing phone number lookup by automatically recognizing phone numbers and looking them up in a reverse phone number lookup database.
  • Providing additional integration between BlackBerry device applications and third party applications by enabling users to seamlessly transition between applications based on string patterns.

Since pattern matching provides a starting point for the application, your application should be configured as an auto-start system module so that all of the components can be registered upon startup, as described in the knowledge base article referenced below. If you review the ZipCodeLookupSample sample application – which can be downloaded from the knowledge base article – it underlines a United States zip code and allows the BlackBerry smartphone user to look up more information on this zip code.

Please share your experiences in using pattern matching by posting your comments! Also, stay tuned for part two of this blog post, as we look into integrating through URLs using CHAPI, BrowserContentProvider and HTTPFilter.

Join the conversation

Show comments Hide comments
+ -
  • Marc Paradise

    This is neat – but is there ever chance of seeing the basic pattern matching functionality extracted into its own component?

    Also a question: what happens if two applications register for the same pattern, such as a zip code or phone number?

  • Marc_Paradise

    (This may show up as a re-post – my comment is not displaying for some reason, even after several refreshes. )
    This is useful, but is there any chance we'll see regex support for strings broken out into a separate API?

    My other question is – what happens when several different applications register for the same string (such as phone number, or #hashtags)?

  • max

    can we match pattern in mail in html format?

  • Amri Shodiq

    I tried the sample app given by this tutorial. It works good matching 5 digits in messages, an notes. Unfortunately the string pattern matching does not seems to works in Blackberry’s browser? Am I missing something or the browser excluded from this API?

  • Swathinv

    I noticed that it doesn’t work in SMS messages either. Is that too excluded? Any observations?

blog comments powered by Disqus