Upd. I am updating this post because VK has released the official sdk https://vk.com/dev/android_sdk . You must use it now for any purpose, it has documentation for all your needs.
Ok, here is a solution that works great, I tried it myself:
Download VKontakte SDK for Android: https://github.com/thest1/Android-VKontakte-SDK .
1) Upload the image to the server with the function form here: https://github.com/devindi/Android-VKontakte-SDK/commit/342acbe76e97181fd1f09820504e47249c962640
public Photo uploadPhotoToWall(String filePath, long userID){ try { String uploadServer=photosGetWallUploadServer(userID, null); HttpClient client=new DefaultHttpClient(); HttpPost httpPost=new HttpPost(uploadServer); MultipartEntity albumArtEntity = new MultipartEntity(); albumArtEntity.addPart("photo", new FileBody(new File(filePath))); httpPost.setEntity(albumArtEntity); HttpResponse response=client.execute(httpPost); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); StringBuilder builder = new StringBuilder(); for (String line; (line = reader.readLine()) != null;) { builder.append(line).append("\n"); } JSONObject photoObject = new JSONObject(builder.toString()); return saveWallPhoto(photoObject.get("server").toString(), photoObject.get("photo").toString(), photoObject.get("hash").toString(), userID, null).get(0); } catch (IOException e) { e.printStackTrace();
2) This function will return the photo identifier, so you can use the wall. savePost () to place the bitmap. Like this:
long photoPid = account.api.uploadPhotoToWall(bitmapFilePath, account.user_id).pid; Collection<String> attachments = new ArrayList<String>(); String att = "photo" + account.user_id + "_" + photoPid; attachments.add(att); api.createWallPost(account.user_id, text, attachments, null, false, false, false, null, null, null, null);
If you have any questions, feel free to ask.