Android转到实际的短信对话

时间:2014-01-06 11:28:57

标签: android

我正在研究应用程序,检查是否通过短信接收器发送了新的短信,如果是,我正在显示通知。单击通知时,我打开默认的短信消息应用程序,如下所示:

  // start default messenging app on notification click
  Intent resultIntent = new Intent(Intent.ACTION_MAIN);
  resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
    | Intent.FLAG_ACTIVITY_SINGLE_TOP
    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  resultIntent.setType("vnd.android-dir/mms-sms");

  TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
  stackBuilder.addParentStack(MainActivity.class);

  // Adds the Intent that starts the Activity to the top of the stack
  stackBuilder.addNextIntent(resultIntent);
  PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
    PendingIntent.FLAG_UPDATE_CURRENT);
  mBuilder.setContentIntent(resultPendingIntent);

这很好用。然而,无论如何实际上进入实际对话的短信收到的数字,而不是只是打开默认的短信应用程序?换句话说,我想进入收到短信的对话,而不仅仅是所有接收者所在的默认主要收件箱。谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

没关系,我自己又找到了答案:

public static Intent getSmsToIntent(Context context, String phoneNumber) {

    Intent popup = new Intent(Intent.ACTION_SENDTO);

    // Should *NOT* be using FLAG_ACTIVITY_MULTIPLE_TASK however something
    // is broken on
    // a few popular devices that received recent Froyo upgrades that means
    // this is required
    // in order to refresh the system compose message UI
    int flags = Intent.FLAG_ACTIVITY_NEW_TASK |
    // Intent.FLAG_ACTIVITY_SINGLE_TOP |
            Intent.FLAG_ACTIVITY_CLEAR_TOP;
    // Intent.FLAG_ACTIVITY_MULTIPLE_TASK;

    popup.setFlags(flags);

    if (!"".equals(phoneNumber)) {
        // Log.v("^^Found threadId (" + threadId +
        // "), sending to Sms intent");
        popup.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
    } else {
        return getSmsInboxIntent(context);
    }
    return popup;
}