Advertisement
Guest User

Untitled

a guest
Oct 19th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. package com.example.myapp;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import com.vk.sdk.*;
  10. import com.vk.sdk.api.*;
  11.  
  12. public class MyActivity extends Activity{
  13.     private static String[] sMyScope = new String[]{VKScope.FRIENDS, VKScope.WALL, VKScope.PHOTOS, VKScope.NOHTTPS};
  14.     private static String appID="4596510";
  15.     @Override
  16.     protected void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.main);
  19.         VKSdk.initialize(new VKSdkListener() {
  20.             @Override
  21.             public void onCaptchaError(VKError captchaError) {
  22.  
  23.             }
  24.  
  25.             @Override
  26.             public void onTokenExpired(VKAccessToken expiredToken) {
  27.  
  28.             }
  29.  
  30.             @Override
  31.             public void onAccessDenied(VKError authorizationError) {
  32.  
  33.             }
  34.         },appID);
  35.         Button button = (Button) findViewById(R.id.button);
  36.  
  37.         button.setOnClickListener(new View.OnClickListener() {
  38.             @Override
  39.             public void onClick(View v) {
  40.  
  41.                 VKSdk.authorize(sMyScope,true,false);
  42.                 VKRequest request = VKApi.wall().post(VKParameters.from(VKApiConst.OWNER_ID, "-60479154", VKApiConst.MESSAGE, "Привет, друзья!"));
  43.                 request.attempts = 10;
  44.                 request.executeWithListener(new VKRequest.VKRequestListener() {
  45.                     @Override
  46.                     public void onComplete(VKResponse response) {
  47.                     }
  48.                     @Override
  49.                     public void onError(VKError error) {
  50.                         Log.e("Log", String.valueOf(error.VK_API_ERROR+"   "+error.apiError+"   "+error.httpError));
  51.                     }
  52.                     @Override
  53.                     public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) {
  54.                     }
  55.                 });
  56.             }
  57.         });
  58.     }
  59.  
  60.     @Override
  61.     protected void onResume() {
  62.         super.onResume();
  63.         VKUIHelper.onResume(MyActivity.this);
  64.     }
  65.  
  66.     @Override
  67.     protected void onDestroy() {
  68.         super.onDestroy();
  69.         VKUIHelper.onDestroy(MyActivity.this);
  70.     }
  71.  
  72.     @Override
  73.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  74.         super.onActivityResult(requestCode, resultCode, data);
  75.         VKUIHelper.onActivityResult(MyActivity.this,requestCode,resultCode,data);
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement