Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓手机短信使用相同的主体和相同的接收者_Java_Android_Android Intent_Sms - Fatal编程技术网

Java 安卓手机短信使用相同的主体和相同的接收者

Java 安卓手机短信使用相同的主体和相同的接收者,java,android,android-intent,sms,Java,Android,Android Intent,Sms,因此,我的android应用程序会检测到位置的变化,然后通知用户,并让用户拨打电话或发送短信 短信被发送到一个保存的号码,其正文是“我在”+完整地址 private NotificationCompat.Builder buildNormal(CharSequence pTitle,String fullAddress) { NotificationCompat.Builder builder = new NotificationCompat.Builder( t

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

短信被发送到一个保存的号码,其正文是
“我在”+完整地址

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.android-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(android.R.drawable.ic_menu_call, "Call", pIntent);
        builder.addAction(android.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(android.)
    // 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\u视图
更改为
ACTION\u发送
ACTION\u发送
,但都没有成功

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


请提供帮助。

当您的应用程序请求一个
挂起内容时,系统会代表您的应用程序保留一个令牌,以执行一个操作,就像您的应用程序正在实际执行一样。这样做的目的是,即使你的应用程序被终止,任何接收到
pendingent
的进程都可以继续执行它

创建这些令牌时,会记录某些信息,例如操作、操作等。如果您的应用程序请求另一个具有相同信息的
pendingent
,则会返回相同的令牌。现在,用于确定它们是否相同或不同的信息不包括
意图本身携带的额外信息。因此,当你的应用程序只使用不同的
额外功能请求相同的SMS操作时,你将一次又一次地使用原始额外功能获得相同的令牌,除非你传递一个标志以表示不同

关于标志:<代码> FraskCopyLelEng/Engult>确保只有给定新数据的实体才能够启动它。如果这个保证不是问题,请考虑<代码> FraveUpDeaEngEng/<代码>。“在你的情况下,我不认为这是一个问题,所以<代码> FraveUpDeTeEngury应该足够了。如果是问题,请使用

标志\u取消\u当前


引用的内容直接来自。

pendingent
s可重复使用。尝试调用
getActivity()
,并将
pendingent.FLAG\u UPDATE\u CURRENT
pendingent.FLAG\u CANCEL\u CURRENT
作为最后一个参数。@Mike M.您能解释添加这些标志的确切作用吗?这解决了问题吗?如果是这样的话,我会在回答中给出一个比我在评论中能找到的更好的解释。是的,它解决了这个问题。但我不确定要添加哪个标志,或者我应该同时添加这两个标志;我在手机上。顺便说一下,你只需要一个。就你而言,我相信两者都可以。我会在回答中解释得更好一点。