A
A
Andrey Zhidenko2016-11-03 13:48:15
Android
Andrey Zhidenko, 2016-11-03 13:48:15

How to get a list of online friends (VKApi)?

To get a list of all friends, I do the following query:

friendsListView = (ListView) view.findViewById(R.id.allFriendsList);
        VKRequest request = VKApi.friends().get(VKParameters.from(VKApiConst.FIELDS, "first_name, last_name"));
        request.executeSyncWithListener(new VKRequest.VKRequestListener() {
            @Override
            public void onComplete(VKResponse response) {
                super.onComplete(response);

                VKList list = (VKList) response.parsedModel;
                ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_expandable_list_item_1, list);

                friendsListView.setAdapter(arrayAdapter);
            }
        });

everything works fine, but what about the getOnline() method?
What parameters should be passed there?
As soon as I tried and everything was unsuccessful.
In theory, the request should look like this?
VKRequest request = VKApi.friends().getOnline(VKParameters.from(VKApiConst.FIELDS, "online"));

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Myvrenik, 2016-11-03
@gim0

Judging by the example in the documentation , if the online_mobile flag is not set to 1, then instead of the JSON object {online:[], online_mobile:[]} , just a JSON list with IDs comes, and you filter the result by the non-existent "online" key.

B
bot8, 2016-11-04
@bot8

VKRequest request = new VKRequest("friends.getOnline");

В ответ вы получите список из id друзей текущего пользователя которые находятся в онлайне. Можете посмотреть что вы получите.

Андрей Жиденко, 2016-11-03
@jamguranga Автор вопроса

А как выставить значение флага? метод from принимает key-value, но как это правильно задать?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question