当用户设备收到短信时,如何启动活动或动画?我想在短信进入查看我的应用程序时开始/播放动画。我该怎么做呢?
答案 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
并采取相应行动
如果您使用过搜索,请执行以下示例: