com.vk.sdk.api.VKError Java Examples
The following examples show how to use
com.vk.sdk.api.VKError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentProfile.java From uPods-android with Apache License 2.0 | 6 votes |
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { mTwitterAuthClient.onActivityResult(requestCode, resultCode, data); if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() { @Override public void onResult(VKAccessToken token) { initUIAfterLogin(); } @Override public void onError(VKError error) { } })) { super.onActivityResult(requestCode, resultCode, data); } else { super.onActivityResult(requestCode, resultCode, data); } }
Example #2
Source File: AudioListFragment.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
private void removeAudio(VKApiAudio audio, int position) { VKApi.audio().delete(VKParameters.from("audio_id", audio.id, "owner_id", audio.owner_id)).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { try { int responseCode = response.json.getInt("response"); if (responseCode == 1) { audioArray.remove(position); adapter.notifyItemRemoved(position); Snackbar.make(binding.getRoot(), R.string.track_removed, Snackbar.LENGTH_SHORT).show(); } } catch (JSONException e) { onError(null); } } @Override public void onError(VKError error) { Snackbar.make(binding.getRoot(), R.string.error_deleting_track, Snackbar.LENGTH_LONG).show(); } }); }
Example #3
Source File: LoginActivity.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
@Override protected void onActivityResult(final int requestCode, int resultCode, Intent data) { if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() { @Override public void onResult(final VKAccessToken accessToken) { createUserComponentAndLaunchMainActivity(); } @Override public void onError(VKError error) { new AlertDialog.Builder(LoginActivity.this) .setMessage("Login failed: " + error.errorReason) .setPositiveButton(android.R.string.ok, null) .show(); } })) { super.onActivityResult(requestCode, resultCode, data); } }
Example #4
Source File: VKShareDialogDelegate.java From cordova-social-vk with Apache License 2.0 | 6 votes |
@Override public void onClick(View view) { setIsLoading(true); if (mAttachmentImages != null && VKSdk.getAccessToken() != null) { final Long userId = Long.parseLong(VKSdk.getAccessToken().userId); VKUploadWallPhotoRequest photoRequest = new VKUploadWallPhotoRequest(mAttachmentImages, userId, 0); photoRequest.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { VKPhotoArray photos = (VKPhotoArray) response.parsedModel; VKAttachments attachments = new VKAttachments(photos); makePostWithAttachments(attachments); } @Override public void onError(VKError error) { setIsLoading(false); if (mListener != null) { mListener.onVkShareError(error); } } }); } else { makePostWithAttachments(null); } }
Example #5
Source File: AddTrackToPlaylistDialogFragment.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); binding.loadingIndicator.setVisibility(View.VISIBLE); VKApi.audio().getAlbums(VKParameters.from(VKApiConst.OWNER_ID, user.getId())).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { VkApiAlbumArrayResponse albumsResponse = gson.fromJson(response.responseString, VkApiAlbumArrayResponse.class); playlists.clear(); playlists.addAll(albumsResponse.getResponse().getItems()); for (VkApiAlbum album : playlists) { String fixedTitle; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { fixedTitle = Html.fromHtml(album.getTitle(), Html.FROM_HTML_MODE_LEGACY).toString(); } else { fixedTitle = Html.fromHtml(album.getTitle()).toString(); } album.setTitle(fixedTitle); } adapter.notifyDataSetChanged(); binding.loadingIndicator.setVisibility(View.GONE); } @Override public void onError(VKError error) { binding.loadingIndicator.setVisibility(View.VISIBLE); Snackbar.make(binding.rcvPlaylists, "Error loading playlists", Snackbar.LENGTH_LONG).show(); } }); }
Example #6
Source File: VKServiceActivity.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == VKServiceType.Authorization.getOuterCode() || requestCode == VKServiceType.Validation.getOuterCode()) { VKSdk.processActivityResult(this, resultCode, data, new VKCallback<VKAccessToken>() { @Override public void onResult(VKAccessToken res) { setResult(VKSdk.RESULT_OK); finish(); } @Override public void onError(VKError error) { Object o = VKObject.getRegisteredObject(getRequestId()); if (o instanceof VKError) { VKError vkError = ((VKError) o); if (vkError.request != null) { vkError.request.cancel(); if (vkError.request.requestListener != null) { vkError.request.requestListener.onError(error); } } } if (error != null) { setResult(VKSdk.RESULT_ERROR, getIntent().putExtra(VKSdk.EXTRA_ERROR_ID, error.registerObject())); } else { setResult(VKSdk.RESULT_ERROR); } finish(); } }); } }
Example #7
Source File: VKServiceActivity.java From cordova-social-vk with Apache License 2.0 | 5 votes |
public static void interruptWithError(Context ctx, VKError apiError, VKServiceType type) { Intent intent = createIntent(ctx, type); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(KEY_REQUEST, apiError.registerObject()); if (ctx != null) { ctx.startActivity(intent); } }
Example #8
Source File: VKOpenAuthDialog.java From cordova-social-vk with Apache License 2.0 | 5 votes |
public void show(@NonNull Activity activity, Bundle bundle, int reqCode, @Nullable VKError vkError) { mVkError = vkError; mBundle = bundle; mReqCode = reqCode; mView = View.inflate(activity, R.layout.vk_open_auth_dialog, null); mProgress = mView.findViewById(R.id.progress); mWebView = (WebView) mView.findViewById(R.id.copyUrl); final Dialog dialog = new Dialog(activity, R.style.VKAlertDialog); dialog.setContentView(mView); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { dialog.dismiss(); } }); dialog.setOnDismissListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { dialog.getWindow().setStatusBarColor(Color.TRANSPARENT); } mDialog = dialog; mDialog.show(); loadPage(); }
Example #9
Source File: VKShareDialogDelegate.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private void makePostWithAttachments(VKAttachments attachments) { if (attachments == null) { attachments = new VKAttachments(); } if (mExistingPhotos != null) { attachments.addAll(mExistingPhotos); } if (mAttachmentLink != null) { attachments.add(new VKApiLink(mAttachmentLink.linkUrl)); } String message = mShareTextField.getText().toString(); final Long userId = Long.parseLong(VKSdk.getAccessToken().userId); VKRequest wallPost = VKApi.wall().post(VKParameters.from(VKApiConst.OWNER_ID, userId, VKApiConst.MESSAGE, message, VKApiConst.ATTACHMENTS, attachments.toAttachmentsString())); wallPost.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onError(VKError error) { setIsLoading(false); if (mListener != null) { mListener.onVkShareError(error); } } @Override public void onComplete(VKResponse response) { setIsLoading(false); VKWallPostResult res = (VKWallPostResult) response.parsedModel; if (mListener != null) { mListener.onVkShareComplete(res.post_id); } dialogFragmentI.dismissAllowingStateLoss(); } }); }
Example #10
Source File: VKSyncRequestUtil.java From cordova-social-vk with Apache License 2.0 | 5 votes |
@Override public void onError(VKError error) { synchronized (this.syncObj) { try { listener.onError(error); } catch (Exception e) { // nothing } isFinish = true; syncObj.notifyAll(); } }
Example #11
Source File: VKSdk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
/** * Checks if an access token exist and performs a try to use it again * * @param context An application context for store an access token * @param loginStateCallback if callback specified, {@link VKCallback#onResult(Object)} method will be called after login state changed * @return true, if an access token exists and not expired */ public static boolean wakeUpSession(@NonNull final Context context, final VKCallback<LoginState> loginStateCallback) { final Context appContext = context.getApplicationContext(); VKUIHelper.setApplicationContext(appContext); VKAccessToken token = VKAccessToken.currentToken(); if (token != null && token.accessToken != null && !token.isExpired()) { forceLoginState(LoginState.Pending, loginStateCallback); trackVisitor(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { updateLoginState(context, loginStateCallback); } @Override public void onError(VKError error) { //Possible double call of access token invalid if (error != null && error.apiError != null && error.apiError.errorCode == 5) { onAccessTokenIsInvalid(appContext); } updateLoginState(context, loginStateCallback); } }); return true; } updateLoginState(context, loginStateCallback); return false; }
Example #12
Source File: VKSdk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
public static boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data, @NonNull VKCallback<VKAccessToken> vkCallback) { if (requestCode == VKServiceActivity.VKServiceType.Authorization.getOuterCode()) { if (resultCode == VKSdk.RESULT_OK) { vkCallback.onResult(VKAccessToken.currentToken()); } else if (resultCode == VKSdk.RESULT_ERROR) { vkCallback.onError((VKError) VKObject.getRegisteredObject(data == null ? 0 : data.getLongExtra(VKSdk.EXTRA_ERROR_ID, 0))); } return true; } else { return false; } }
Example #13
Source File: SocialVk.java From cordova-social-vk with Apache License 2.0 | 5 votes |
private boolean share(final String url, final String comment, final String imageUrl) { if(url == null || comment == null) return false; new AsyncTask<String, Void, String>() { private Bitmap image = null; @Override protected String doInBackground(String... args) { if(imageUrl != null) image = getBitmapFromURL(imageUrl); return ""; } @Override protected void onPostExecute(String result) { VKShareDialog vsh = new VKShareDialog() .setText(comment) .setAttachmentLink("", url) .setShareDialogListener(new VKShareDialog.VKShareDialogListener() { public void onVkShareComplete(int postId) { Log.i(TAG, "VK sharing complete"); } public void onVkShareCancel() { Log.i(TAG, "VK sharing cancelled"); } public void onVkShareError(VKError err) { Log.e(TAG, err.toString()); } }); if(image != null) { vsh.setAttachmentImages(new VKUploadImage[]{ new VKUploadImage(image, VKImageParameters.pngImage()) }); } vsh.show(getActivity().getFragmentManager().beginTransaction(), "VK_SHARE_DIALOG"); } }.execute(); savedUrl = null; savedComment = null; savedImageUrl = null; return true; }
Example #14
Source File: RadioFragment.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
public void loadRadio(@Nullable VKApiAudio radioTrack, @Nullable Action0 onCompletedCallback) { binding.loadingIndicator.setVisibility(View.VISIBLE); VKParameters parameters; if (radioTrack == null) { parameters = VKParameters.from(VKApiConst.COUNT, 100, "shuffle", 1); } else { parameters = VKParameters.from("target_audio", radioTrack.owner_id + "_" + radioTrack.id, VKApiConst.COUNT, 100, "shuffle", 1); } VKApi.audio().getRecommendations(parameters).executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { audioArray.clear(); audioArray.addAll((VkAudioArray) response.parsedModel); adapter.notifyDataSetChanged(); binding.loadingIndicator.setVisibility(View.GONE); if (audioArray.size() == 0) { Snackbar.make(binding.getRoot(), R.string.no_similar_tracks, Snackbar.LENGTH_LONG).show(); binding.noData.getRoot().setVisibility(View.VISIBLE); } else { binding.noData.getRoot().setVisibility(View.GONE); } if (onCompletedCallback != null) onCompletedCallback.call(); } @Override public void onError(VKError error) { Snackbar.make(binding.rcvAudio, R.string.error_loading_radio, Snackbar.LENGTH_LONG); binding.loadingIndicator.setVisibility(View.GONE); } }); }
Example #15
Source File: VKSdk.java From cordova-social-vk with Apache License 2.0 | 4 votes |
/** * Common check for access denied errors * * @param apiError error from VKRequest */ public static void notifySdkAboutApiError(VKError apiError) { if (apiError.errorCode == 5) { onAccessTokenIsInvalid(VKUIHelper.getApplicationContext()); } }
Example #16
Source File: VKSdk.java From cordova-social-vk with Apache License 2.0 | 4 votes |
public CheckTokenResult(VKError err) { this.error = err; }
Example #17
Source File: VKSdk.java From cordova-social-vk with Apache License 2.0 | 4 votes |
/** * Pass data of onActivityResult() function here * * @param resultCode result code of activity result * @param result intent passed by activity * @param callback activity result processing callback * @return If SDK parsed activity result properly, returns true. You can return from onActivityResult(). Otherwise, returns false. */ static boolean processActivityResult(@NonNull Context ctx, int resultCode, @Nullable Intent result, @Nullable VKCallback<VKAccessToken> callback) { if (resultCode != Activity.RESULT_OK || result == null) { //Result isn't ok, maybe user canceled if (callback != null) { callback.onError(new VKError(VKError.VK_CANCELED)); } updateLoginState(ctx); return false; } CheckTokenResult tokenResult; Map<String, String> tokenParams = null; if (result.hasExtra(VKOpenAuthDialog.VK_EXTRA_TOKEN_DATA)) { //Token received via webview String tokenInfo = result.getStringExtra(VKOpenAuthDialog.VK_EXTRA_TOKEN_DATA); tokenParams = VKUtil.explodeQueryString(tokenInfo); } else if (result.getExtras() != null) { //Token received via VK app tokenParams = new HashMap<>(); for (String key : result.getExtras().keySet()) { tokenParams.put(key, String.valueOf(result.getExtras().get(key))); } } tokenResult = checkAndSetToken(ctx, tokenParams); if (tokenResult.error != null && callback != null) { callback.onError(tokenResult.error); } else if (tokenResult.token != null) { if (tokenResult.oldToken != null) { VKRequest validationRequest = VKRequest.getRegisteredRequest(result.getLongExtra(VKOpenAuthDialog.VK_EXTRA_VALIDATION_REQUEST, 0)); if (validationRequest != null) { validationRequest.unregisterObject(); validationRequest.repeat(); } } else { trackVisitor(null); } if (callback != null) { callback.onResult(tokenResult.token); } } requestedPermissions = null; updateLoginState(ctx); return true; }
Example #18
Source File: AudioListFragment.java From vk_music_android with GNU General Public License v3.0 | 4 votes |
public void loadData() { binding.swiperefresh.setRefreshing(true); VKParameters parameters = null; switch (listType) { case MY_AUDIO: parameters = VKParameters.from(); break; case PLAYLIST: parameters = VKParameters.from(VKApiConst.ALBUM_ID, playlist.getId()); break; case SEARCH: parameters = VKParameters.from(VKApiConst.Q, searchQuery, VKApiConst.COUNT, 100); break; case POPULAR: parameters = VKParameters.from("only_eng", 1); break; } VKRequest.VKRequestListener listener = new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { audioArray.clear(); audioArray.addAll((VkAudioArray) response.parsedModel); adapter.notifyDataSetChanged(); binding.swiperefresh.setRefreshing(false); if (audioArray.size() == 0) { binding.noData.getRoot().setVisibility(View.VISIBLE); } else { binding.noData.getRoot().setVisibility(View.GONE); } } @Override public void onError(VKError error) { Snackbar.make(binding.rcvAudio, "Error loading search results", Snackbar.LENGTH_LONG); binding.swiperefresh.setRefreshing(false); } }; if (listType == AudioListType.SEARCH) { VKApi.audio().search(parameters).executeWithListener(listener); } else if (listType == AudioListType.POPULAR) { VKApi.audio().getPopular(parameters).executeWithListener(listener); } else { VKApi.audio().get(parameters).executeWithListener(listener); } }
Example #19
Source File: VKCaptchaDialog.java From cordova-social-vk with Apache License 2.0 | 2 votes |
public VKCaptchaDialog(VKError captchaError) { mCaptchaError = captchaError; }
Example #20
Source File: VKAbstractOperation.java From cordova-social-vk with Apache License 2.0 | votes |
public abstract void onError(OperationType operation, VKError error);
Example #21
Source File: VKCallback.java From cordova-social-vk with Apache License 2.0 | votes |
void onError(VKError error);
Example #22
Source File: VKShareDialogBuilder.java From cordova-social-vk with Apache License 2.0 | votes |
void onVkShareError(VKError error);