Task : when turning on the application, check the validity of the VKAccessToken received in the previous session.

Problem : The method that listens for AccessToken'a changes does not work.


After authorizing a user, I receive the VKAccessToken , via onActivityResult and save it in Preferences . But, when the application is turned on, I need to somehow find out its validity (which will guarantee that the user has not changed the password or something else).

For the "wiretapping" of validity changes - I launch the VKAccessTokenTracker listener, as written in VK Api:

  public class Application extends android.app.Application { private static final String TAG = "RostislavLOG"; //Временная переменная для откладки private VKAccessTokenTracker vkAccessTokenTracker = new VKAccessTokenTracker() { @Override public void onVKAccessTokenChanged(VKAccessToken oldToken, VKAccessToken newToken) { if (newToken == null) { Log.i(TAG, "VKAccessToken is invalid"); } else { Log.i(TAG, "VKAccessToken is valid"); } } }; @Override public void onCreate() { super.onCreate(); //Инициализация VK Api VKSdk.initialize(this); vkAccessTokenTracker.startTracking(); } } 

However, the onVKAccessTokenChanged method onVKAccessTokenChanged not start when the application is turned on, and does not react in any way to changing the password (both the included application and the one just launched).


So how does one know the validity of VKAccessToken ?

  • And how does the isLoggedIn method behave after changing the password? .. - Yuriy SPb
  • @Yuriy SPb, what isLoggined ? - user189127
  • This one: VKSdk.isLoggedIn() - Yuriy SPb
  • @YuriSPb, almost. After I entered, it says true , but when I changed the password, it was also true . The methods are interrelated, apparently. - user189127
  • Google is silent on this account. A quick review of the sources of vkshnogo sdk also didn’t clarify anything to me ... Maybe you need to check trying to do something, get an error with a message about an invalid token and then ask for authorization? that the token is valid still. - Yuriy SPb

0