Initialization and login

suggest change
  1. Create a new application here: create application
  2. Choose standalone applicaton and confirm app creation via SMS.
  3. Fill Package namefor Android as your current package name. You can get your package name inside android manifest file, at the very begginning.
  4. Get your Certificate fingerprint by executing this command in your shell/cmd:

keytool -exportcert -alias androiddebugkey -keystore path-to-debug-or-production-keystore -list -v

You can also get this fingerprint by SDK itself:

String[] fingerprints = VKUtil.getCertificateFingerprint(this, this.getPackageName());
Log.d("MainActivity", fingerprints[0]);
  1. Add recieved fingerprint into your Signing certificate fingerprint for Android: field in Vk app settings (where you entered your package name)
  2. Then add this to your gradle file:

compile ‘com.vk:androidsdk:1.6.5’

  1. Initialize the SDK on startup using the following method. The best way is to call it in the Applications onCreate method.
private static final int VK_ID = your_vk_id;
public static final String VK_API_VERSION = "5.52"; //current version
@Override
    public void onCreate() {
        super.onCreate();
        VKSdk.customInitialize(this, VK_ID, VK_API_VERSION);
}

This is the best way to initizlize VKSdk. Don’t use the methid where VK_ID should be placed inside strings.xml because api will not work correctly after it.

  1. Final step is to login using vksdk.
public static final String[] VK_SCOPES = new String[]{
        VKScope.FRIENDS,
        VKScope.MESSAGES,
        VKScope.NOTIFICATIONS,
        VKScope.OFFLINE,
        VKScope.STATUS,
        VKScope.STATS,
        VKScope.PHOTOS
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    someButtonForLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           VKSdk.login(this, VK_SCOPES); 
        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() {
        @Override
        public void onResult(VKAccessToken res) {
            res.accessToken; //getting our token here.
        }

        @Override
        public void onError(VKError error) {
            Toast.makeText(SocialNetworkChooseActivity.this,
                    "User didn't pass Authorization", Toast.LENGTH_SHORT).show();
        }
    });
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Vk SDK:
* Initialization and login

Table Of Contents
2 Gradle
5 Intent
17 Service
19 WebView
31 SQLite
35 Glide
37 Dialog
38 ACRA
44 Handler
53 Toast
63 Menu
65 Picasso
70 Volley
71 Widgets
78 Realm
90 Spinner
95 OkHttp
108 TextView
109 ListView
111 Loader
118 Xposed
119 Security
121 ImageView
123 Doze Mode
130 Drawables
131 Colors
134 Fresco
139 AdMob
145 Keyboard
146 Button
150 EditText
155 Vk SDK
163 ExoPlayer
169 XMPP
175 OpenCV
177 Threads
184 ORMLite
186 TabLayout
190 LruCache
192 Zip files
194 Fastlane
199 FileIO
202 Moshi
210 VideoView
216 Paint
218 ProGuard
226 CleverTap
228 ADB shell
229 Ping ICMP
230 AIDL
234 Context
240 JCodec
242 Okio
249 FuseView
254 Looper
261 Fastjson
263 Jackson
267 Smartcard