我的应用程序为收到的每条短信创建通知:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setContentTitle(context.getString(R.string.notif_title))
.setContentText(sms_from+": "+sms_body);
Intent mIntent = new Intent(context, DialogActivity.class);
mIntent.putExtra("sms_body", sms_body);
mIntent.putExtra("sms_from", sms_from);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent mPendingIntent =
PendingIntent.getActivity(
context,
0,
mIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(mPendingIntent);
一旦用户点击通知,DialogActivity
打开,当我提取数据时:
public class DialogActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String sms_body = getIntent().getExtras().getString("sms_body");
final String sms_from = getIntent().getExtras().getString("sms_from");
它适用于一条短信/通知。但是,如果接收到多个 SMS,则sms_from
提取sms_body
的onCreate
总是包含最后一条 SMS 的文本。我应该如何解决这个问题?