How can I get a number placed in a text message on Android?

121 views Asked by At

I want to add a feature to my app that when I touch the number in a message, the user can decide to send the number to my app or Android Dialer.

For example my friend send me a code and i want to use this code for special ussd code that my app run it.

I think I have to use implicit intent but I don't know how?

Thanks

2

There are 2 answers

2
Maulik Sheth On

I assume you are talking about a number in a SMS that you received. On clicking that number you want the user to get an option to either dial or use your app.

If yes then you need to include intent filter in your manifest file for launcher activity.

1
Srinath Ganesh On

I have quoted the below links

-intent filter

-Intents implicit\explicit

Implicit intents specify the action which should be performed and optionally data which provides data for the action.

For example the following tells the Android system to view a webpage. All installed web browsers should be registered to the corresponding intent data via an intent filter.

Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.vogella.com")); startActivity(i); 

If an Explicit intent is send to the Android system, it searches for all components which are registered for the specific action and the fitting data type.

If only one component is found, Android starts this component directly. If several components are identifier by the Android system, the user will get an selection dialog and can decide which component should be used for the intent.


How to use

You can register your own components via Intent filters. If a component does not define one, it can only be called by explicit intent.


Register an activity as Browser

<activity android:name=".BrowserActivitiy" 
          android:label="@string/app_name">
  <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:scheme="http"/> 
  </intent-filter>
</activity>

UPDATES

A code sample for mimeType

<activity android:name="ShareActivity">
<intent-filter>
    <action android:name="android.intent.action.SEND"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="text/plain"/>
    <data android:mimeType="image/*"/>
</intent-filter>