Steve C.
Steve C.

Reputation: 1353

How to instantiate activity based on received sms?

How would I have an activity or animation start when the users device receives an sms? I want to start/play an animation when a sms comes in while they are viewing my app. How would I go about doing that?

Upvotes: 0

Views: 104

Answers (2)

prvn
prvn

Reputation: 916

public class SmsReceiver extends BroadcastReceiver {

private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";



@Override
public void onReceive(Context context, Intent intent) {     

    if (intent.getAction().equals(SMS_RECEIVED)) {
               // here start the activity for animation or whatever you want to do
            }
      }
}

add this permission to your manifest

<uses-permission android:name="android.permission.RECEIVE_SMS"/>

add the receiver under your application tag in your manifest

<receiver android:name=".SmsReceiver" >
        <intent-filter android:priority="999">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" >
            </action>
        </intent-filter>
    </receiver> 

Upvotes: 2

Blundell
Blundell

Reputation: 76536

Create a BroadcastReceiver for SMS

http://developer.android.com/reference/android/content/BroadcastReceiver.html

and act accordingly

SO Example if you had used search:

Android - SMS Broadcast receiver

Upvotes: 0

Related Questions