有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java安卓手机短信使用相同的主体和相同的收件人

所以我的安卓应用程序会检测到位置的变化,然后通知用户,并让用户拨打电话或发送短信

短信被发送到一个已保存的号码,其正文为"I'm at " + fullAddress

private NotificationCompat.Builder buildNormal(CharSequence pTitle,String fullAddress) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            this);

    Intent in = new Intent(this,MainActivity.class);
    PendingIntent pMainIntent = PendingIntent.getActivity(this, 0,
            in, 0);

    if(getSavedDataString("gNumber")!=null) 
    {
        String url = getSavedDataString("gNumber");
        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

        //Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:" 
        //+ Uri.encode(getSavedDataString("gNumber").substring(4))));
        //intent.setData());
        //startActivity(intent);
        Intent smsIntent = new Intent(Intent.ACTION_VIEW);
        //smsIntent.setType("vnd.安卓-dir/mms-sms");
        smsIntent.putExtra("address", getSavedDataString("gNumber").substring(4));
        smsIntent.putExtra("sms_body","I'm at " + fullAddress);
        smsIntent.setData(Uri.parse("smsto:" 
        + Uri.encode(getSavedDataString("gNumber").substring(4))));
        PendingIntent psmsIntent = PendingIntent.getActivity(this, 0,
                smsIntent, 0);

        builder.addAction(安卓.R.drawable.ic_menu_call, "Call", pIntent);
        builder.addAction(安卓.R.drawable.sym_action_email, "Send SMS", psmsIntent);
    }
    else
    {
        builder.addAction(0, "Choose Guardian", pMainIntent);
    }
    builder.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);
    // set the shown date
    builder.setWhen(System.currentTimeMillis());
    // the title of the notification
    builder.setContentTitle(pTitle);
    // set the text for pre API 16 devices
    builder.setContentText(pTitle);
    // set the action for clicking the notification

    builder.setContentIntent(pMainIntent);
    // set the notifications icon
    builder.setSmallIcon(R.drawable.ic_home);
    //builder.setSound(安卓.)
    // set the small ticker text which runs in the tray for a few seconds
    builder.setTicker("Location Change Alert");
    // set the priority for API 16 devices
    //builder.setVibrate(pattern)
    builder.setPriority(Notification.PRIORITY_DEFAULT);
    return builder;
}

这里显示,向用户显示的通知包含两个调用或发送消息的操作,并将其发送到预存号码gNumber

问题是,我按下了发送短信的操作,然后放弃了该信息,而没有发送该信息,也从草稿中删除了该信息等等。 然后,该应用程序检测到另一个位置变化,因此它会发送一个不同的通知,并使用不同的fullAddress。该意图仍然停留在同一个文本体上

我还试图更改收件人,但它也被旧收件人卡住了。我要么重启设备,要么发送我曾经丢弃的信息

我还试图从ACTION_VIEW变为ACTION_SENDACTION_SENDTO,但都没有成功

我想知道,除了完全改变这个意图并使用SMSManager之外,是否还有其他解决方案可以解决这个意图被困在同一个身体和接收者身上的问题

请帮忙


共 (0) 个答案