如何根据收到的短信实例化活动?

时间:2013-05-16 03:58:42

标签: android eclipse java-ee sms

当用户设备收到短信时,如何启动活动或动画?我想在短信进入查看我的应用程序时开始/播放动画。我该怎么做呢?

2 个答案:

答案 0 :(得分:2)

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
            }
      }
}

将此权限添加到您的清单

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

在清单

中的应用标签下添加接收器
<receiver android:name=".SmsReceiver" >
        <intent-filter android:priority="999">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" >
            </action>
        </intent-filter>
    </receiver> 

答案 1 :(得分:0)

为SMS创建BroadcastReceiver

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

并采取相应行动

如果您使用过搜索,请执行以下示例:

Android - SMS Broadcast receiver