0

I am creating an android application in which I have to parse USSD msgs and get the balance amount to show in my app.

I am able to get ussd msgs through AccessibilityService using this link as string. Now the problem is that how to get the balance amount extracted from these strings. As different carriers have different ussd messages.

For example:

  • Carrier 1: . . . Rs 46.503 . . .
  • Carrier 2: . . . Rs.46.50 . . .

Similarly for data balance:

  • Carrier 1: . . . Mb 1700.53 . . .
  • Carrier 2: . . . 1700.53MB . . .

Where ". . ." means these texts can be in between a sentence, i.e as sub string. I could have just extracted all the numbers but there are various plans info too in these messages, so other numbers are also there apart from the balance one's. I don't have much knowledge to create a regex if this is possible through that.

There are various apps like piBalance, trueBalance which have these features for reference. The red marked text in the following images is what I want to extract. How to do this??

enter image description here enter image description here

Community
  • 1
  • 1
Ashwani Kumar
  • 1,402
  • 1
  • 19
  • 26
  • 1
    For floating number like 0.1, .1, 1.1 this [0-9]*\.[0-9]+ should work. – Math10 Aug 22 '16 at 13:29
  • If it could also be just a whole number, `[0-9]+(\.[0-9]+)?`. – chris85 Aug 22 '16 at 13:54
  • i think you will end with a few templates/combinations of regex per provider and either you ask the user to pick the provider (one time) or you try templates list and use the one that matches the string message. – Yazan Aug 22 '16 at 14:03

0 Answers0