Код: Выделить всё
public class MyActivity extends Activity {
String scope[];
boolean revoke,forceOAuth;
TextView text;
Button btn;
String appId="45311250";
VKSdkListener listener=new VKSdkListener() {
public void onCaptchaError(VKError captchaError) {}
public void onTokenExpired(VKAccessToken expiredToken) {}
public void onAccessDenied(VKError authorizationError) {}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text= (TextView) findViewById(R.id.text);
btn= (Button) findViewById(R.id.btn);
}
public void onClickButton(View v){
VKSdk.initialize(listener, appId);
VKSdk.authorize(scope, revoke, forceOAuth);
VKRequest request = VKApi.users().get();
request.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
text.setText("Подключились");
}
@Override
public void onError(VKError error) {
text.setText(error.errorMessage);
}
@Override
public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) {
text.setText("Иная ошибка");
}
});
}
@Override
protected void onResume() {
super.onResume();
VKUIHelper.onResume(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
VKUIHelper.onDestroy(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
VKUIHelper.onActivityResult(requestCode, resultCode, data);
}
}