Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:55:01+00:00 2026-06-14T04:55:01+00:00

In my application when I have to add a friend I usually do send

  • 0

In my application when I have to add a friend I usually do send subscription packets 4 times
i.e

A->B (subscribe)
B->A ( subscribed)
B-A( subscribe)
A->B ( subscribed)

After each step I see on the server the status changes immediately.

But in my application it only comes to reflect after LOGGING OUT and LOGGING in again.
THE PERSON HAS TO LOGOUT ONCE AFTER HE HAS ADDED A FRIEND AND THEN ONLY THE FRIEND IS SHOWN IN HIS FRIEND LIST>

What’s the problem? I have found a lot but didnot found any error 🙁

No error is showing in the logcat.

I have also printed the syso output after each packet is sent. It always says as NONE ( in the case of the person to whom request is sent ) and Always says TO/FROM ( in the case of the user who has sent the friend request ).. Both is not reflected untill and unless a person logs out and logs in again.

Please help me 🙁

Add Friend Function

public boolean addFriend(String jid) {
        String nickname = null;
        String idExtension = jid+"@abc.hostname.com";
        nickname = StringUtils.parseBareAddress(jid);
        if (!roster.contains(idExtension)) {
            try {   
                roster.createEntry(idExtension, nickname, null);
                //to subscribe the user in the entry
                Presence subscribe = new Presence(Presence.Type.subscribe);
                subscribe.setTo(idExtension);               
                connection.sendPacket(subscribe);   
                return true;

            } catch (XMPPException e) {
                System.err.println("Error in adding friend");
                return false;
            }
        } else {
            return false;
        }
    }

It will send a notification to the other user.. on allowing which this code is written :-

btn_Allow = (Button)findViewById(R.id.btn_manageNotification_ALLOW);
        btn_Allow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                //accept the friends subscription
                Presence subscribed = new Presence(Presence.Type.subscribed);
                subscribed.setTo(id);               
                connection.sendPacket(subscribed);



                mCustomProgressDialog = CustomProgressDialog.createDialog(
                        ManageNotification.this, "", "");
                mCustomProgressDialog.show();   
                mCustomProgressDialog.setCancelable(false); 
                new Thread(){
                    public void run() {

                        try {
                            sleep(5000);
                            //mXmconn.getContactList();

                            /*Presence subscribed = new Presence(Presence.Type.subscribe);
                            subscribed.setTo(id);               
                            System.out.println("The user is :"+id);
                            connection.sendPacket(subscribed);*/

                        } catch (InterruptedException e) {}                     
                        mReturnUserMenu.sendEmptyMessage(0);

                    };
                }.start();
            }
        });

same it is done again on allow again to the user who initiated the request.

Please help. The subscription status is changing on the server instantly but on app it is updating after logout once.

Here is the code which represents the lists

public  void getContactList(){

        roster = connection.getRoster();

        Collection<RosterEntry> entries = roster.getEntries();
        System.out.println("Total=="+entries.size());
        mfriendList.clear();
        mfriendPendingList.clear();
        mfriendRequestList.clear();
        for (RosterEntry entry : entries) {
            mFriendsDataClass = new FriendsDataClass();

            mFriendsDataClass.friendName = entry.getUser().toString();

            String user = entry.getUser();

            int index_of_Alpha = user.indexOf("@");
            /*System.out.println("The current working user is : "+user);
            System.out.println("His status is"+entry.getType().toString());*/
            String subID = user.substring(0, index_of_Alpha);
            Presence availability = roster.getPresence(user);
            Mode userMode = availability.getMode();

            mFriendsDataClass.availability = "";
            mFriendsDataClass.friendNickName = subID;           
            mFriendsDataClass.friendStatus = stusMsg.toString();
            mFriendsDataClass.friendState = retrieveState_mode(availability.getMode(),availability.isAvailable());
            if(entry.getType().toString().equalsIgnoreCase("to")){
                //getContactList();
                mfriendRequestList.add(mFriendsDataClass);
            }else if(entry.getType().toString().equalsIgnoreCase("from")){
                //getContactList();
                mfriendPendingList.add(mFriendsDataClass);
            }else if(entry.getType().toString().equalsIgnoreCase("both")){
                //getContactList();
                mfriendList.add(mFriendsDataClass);
            }           
        }
    }

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:55:03+00:00Added an answer on June 14, 2026 at 4:55 am

    For sending a request you have to use,

    roster.createEntry("mail_id", null, null);
    

    And for Listening the Request you have to listen using PacketListener. And check the Presence

    Presence presence = (Presence) packet;
    Presence presence_request = new Presence(Presence.Type.subscribed);
    presence_request.setTo(presence.getFrom());
    presence_request.setType(Presence.Type.subscribed);
    presence_request.setFrom("current_logged_in_user");
    connection.sendPacket(presence_request);
    roster.createEntry(presence.getFrom(), null, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have application with Listbox and files, each time i press on Add button
I'm working on a Rails application where I have users that can add each
In my chat application when I have to add a friend I have to
I have the following application: I have 1 window. On that window I add
I am developing an application where i will have to add a separate project
I have developend a window application(Win32 API) in visual C++. I have to add
I want to add a thumbnail picture viewer to my application.I have been trying
To execute my application in iPhone first of all I have to add provisioning
I won't create wallpaper-application but have one problem. Please tell me how add ImageView
We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.