3

ユーザーが友達リクエストを受け取ったときの通知を作成しています。通知には承認ボタンと拒否ボタンがあり、ユーザーがクリックした内容に応じて、開始されたアクティビティが要求を処理します。とにかく、ユーザーが同意をクリックすると、開始されたアクティビティは同意というタイトルのリクエストを受け取り、その逆も同様です。しかし、なんらかの異常な理由で、同意をクリックしても拒否しても、リクエスト文字列は拒否を返します。承認または null の送信時に拒否要求文字列をコメント アウトすることもできますが、それでも拒否が返されます。ばかげているだけです。これが私がしたことです。

public void newRequest(String name,String id, String relation){

        Intent intent = new Intent(this, Contacts.class);
        Bundle extras= new Bundle();
        extras.putString("request", "accept");
        extras.putString("relation", relation);
        extras.putString("name", name);
        extras.putString("id", id);


        Intent in = new Intent(this, Contacts.class); 
        Bundle extra= new Bundle();
        extra.putString("request", "decline");
        extra.putString("relation", relation);
        extra.putString("name", name);
        extra.putString("id", id);

        intent.putExtras(extras);
        in.putExtras(extra);
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
        PendingIntent pIn = PendingIntent.getActivity(this, 0, in, 0);

        Notification noti = new NotificationCompat.Builder(this)
            .setContentTitle(name+" sent you have received a friend request")
            .setContentText("Reflap").setSmallIcon(R.drawable.fav)
            .setContentIntent(pIntent)
            .addAction(0, "Accept", pIntent)
            .addAction(0, "Decline", pIn)
            .build();
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        // Hide the notification after its selected
        noti.flags |= Notification.FLAG_AUTO_CANCEL;

        notificationManager.notify(5, noti);

    }

インテントを受け取るアクティビティです

  Intent intent=getIntent();
        //userName=intent.getStringExtra("username");
        Bundle extras=intent.getExtras();
        ///*if(extras.getString("request")!=null){
        try{
        requester=extras.getString("request");
        senderId=extras.getString("id");
        namer=extras.getString("name");
        relation=extras.getString("relation");
        System.out.println("Starting to perform an accept with "+namer+" and user id "+senderId+" and request is "+requester);
        }catch(Exception e){
            e.printStackTrace();
        }

しかし、どのボタンをクリックしても、文字列が拒否を返します。本当に変です。

4

1 に答える 1

6

理解した。問題はここにありました

PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
    PendingIntent pIn = PendingIntent.getActivity(this, 0, in, 0);

どちらも同じコードを要求します。それは違う必要がありました。これは機能します:

PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
    PendingIntent pIn = PendingIntent.getActivity(this, 1, in, 0);
于 2013-08-11T14:19:39.003 に答える