I need to display a photo of my profile vk in any scrolling view (Recycler / List). But, since I am a very newcomer to VKApi, there were some problems. I'm trying to bring at least a list of pictures to the studio console, but so far it’s not really working. Here I throw my MainActivity class. The ID of the page is just one, so as not to burn, this is how I write my own. Checked in the documentation - displays my pictures, everything is fine.

PS This code regularly worked with the output of the texts of the group posts, and then something did not converge.

import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ListView; import com.vk.sdk.VKAccessToken; import com.vk.sdk.VKCallback; import com.vk.sdk.VKSdk; import com.vk.sdk.api.VKApiConst; import com.vk.sdk.api.VKError; import com.vk.sdk.api.VKParameters; import com.vk.sdk.api.VKRequest; import com.vk.sdk.api.VKResponse; import com.vk.sdk.api.model.VKPhotoArray; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class MainActivity extends AppCompatActivity { ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); VKSdk.login(this); listView = (ListView) findViewById(R.id.listView); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() { @Override public void onResult(final VKAccessToken res) { VKRequest vkRequest = new VKRequest("photos.getAll",VKParameters.from(VKApiConst.OWNER_ID, 1), VKPhotoArray.class); vkRequest.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); System.out.println(); VKRequest request = new VKRequest("photos.getAll", VKParameters.from(VKApiConst.OWNER_ID, 1), VKPhotoArray.class); request.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); try { JSONObject jsonObject = (JSONObject) response.json.get("response"); JSONArray jsonArray = (JSONArray) jsonObject.get("items"); for (int i = 0; i < jsonArray.length(); i++){ JSONObject post = (JSONObject) jsonArray.get(i); System.out.println(post.get("src")); } } catch (JSONException e) { e.printStackTrace(); } } }); } }); } @Override public void onError(VKError error) { } })) { super.onActivityResult(requestCode, resultCode, data); } } } 
  • one
    "some problems have arisen" - a very good question) I think you just need to make some corrections) But seriously - no mistakes, no description what is wrong at all. Plus, this is "onActivityResult" - are you sure that it is called at all? Of course, I worked with android for a long time, but EMNIP it is called when you close another activation. And I do not see anything like that. And anyway, if I were you, I would have started the debugger or logged in to see if you really call everything correctly .. - Uraty

1 answer 1

You can do it like this:

 private void VkRequest() { VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "photo_200")); request.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { VKApiUser user = ((VKList<VKApiUser>) response.parsedModel).get(0); String urlImage = user.photo_200; } @Override public void onError(VKError error) {} @Override public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) {} }); } 

All optional parameters can be found here and here .