How to open VKontakte app with a specific friend?

3.4k views Asked by At

Background

In order to open Facebook app with a specific Facebook friend, you can use this intent:

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("fb://profile/%s", friendId)));

A similar solution is found for LinkedIn:

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("linkedin://profile/%s",  friendId)));

I think the next one will work for Google Plus (didn't test it, but it seems promising) :

final Intent intent =new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("https://plus.google.com/%s/posts", friendId)));

The question

I've tried to find how to open VKontakte (VK) social network app using such intents, but couldn't find it.

Is there such an intent? If so, what is it?

3

There are 3 answers

1
Roman Truba On BEST ANSWER

The answer from developer is next:

Yes, it's done the same way:

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("vkontakte://profile/%d", friendId)));

If you need to open a community, use the same URL but add the minus sign to the community ID.

Question answered here

1
Andrew On

Here is a list of url i found at VK app manifest

  • http ://vk.com/.*
  • http ://vkontakte.ru/.*
  • https ://vk.com/.*
  • https ://vkontakte.ru/.*
  • http ://m.vk.com/.*

Note: remove space after http/https. SO won't let me post more than 2 links you can use any of that to launch vk from your app

here is how i do that

 private void sendIntentToVkApp() {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://vk.com/hmrussia"));
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

and here is a part of VK Manifest where all the schemes are defined

<intent-filter>
            <category
                android:name="android.intent.category.DEFAULT"/>
            <action
                android:name="android.intent.action.VIEW"/>
            <data
                android:scheme="vklink"/>
        </intent-filter>
        <intent-filter>
            <action
                android:name="android.intent.action.VIEW"/>
            <category
                android:name="android.intent.category.DEFAULT"/>
            <category
                android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="http"
                android:host="vk.com"
                android:pathPattern="/.*"/>
        </intent-filter>
        <intent-filter>
            <action
                android:name="android.intent.action.VIEW"/>
            <category
                android:name="android.intent.category.DEFAULT"/>
            <category
                android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="http"
                android:host="vkontakte.ru"
                android:pathPattern="/.*"/>
        </intent-filter>
        <intent-filter>
            <action
                android:name="android.intent.action.VIEW"/>
            <category
                android:name="android.intent.category.DEFAULT"/>
            <category
                android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="https"
                android:host="vk.com"
                android:pathPattern="/.*"/>
        </intent-filter>
        <intent-filter>
            <action
                android:name="android.intent.action.VIEW"/>
            <category
                android:name="android.intent.category.DEFAULT"/>
            <category
                android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="https"
                android:host="vkontakte.ru"
                android:pathPattern="/.*"/>
        </intent-filter>
        <intent-filter>
            <action
                android:name="android.intent.action.VIEW"/>
            <category
                android:name="android.intent.category.DEFAULT"/>
            <category
                android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="vkontakte"
                android:pathPattern="/.*"/>
        </intent-filter>
0
kulikovman On

In Kotlin. This will open the app if installed, otherwise the browser will open.

private fun openVk(profileId: String) {
        val uri = Uri.parse("http://vk.com/$profileId")
        val intent = Intent(Intent.ACTION_VIEW, uri)

        startActivity(intent)
    }