Search for existing user using xmpp/UserSearchManager in Android

后端 未结 2 1275
名媛妹妹
名媛妹妹 2020-12-19 23:32

I have gone through this1, this2 and this3 but still cannot find the solution of the problem.

I could know where my problem is what I am doing in this code is:

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 00:24

    Try this. It solves my problem.

    UserSearchManager search = new UserSearchManager(mXMPPConnection);  
    
    Form searchForm = search.getSearchForm("search."+mXMPPConnection.getServiceName());
    
    Form answerForm = searchForm.createAnswerForm();  
    answerForm.setAnswer("Username", true);  
    
    answerForm.setAnswer("search", user);  
    
    org.jivesoftware.smackx.ReportedData data = search.getSearchResults(answerForm,"search."+mXMPPConnection.getServiceName());  
    
    if(data.getRows() != null)
    {
        Iterator it = data.getRows();
        while(it.hasNext())
        {
            Row row = it.next();
            Iterator iterator = row.getValues("jid");
            if(iterator.hasNext())
            {
                String value = iterator.next().toString();
                Log.i("Iteartor values......"," "+value);
            }
            //Log.i("Iteartor values......"," "+value);
        }
        Toast.makeText(_service,"Username Exists",Toast.LENGTH_SHORT).show();
        );
    }
    

    If Server has not any entery with that specified name then Itearator it has no value and code will not go inside while(it.hasNext).

提交回复
热议问题