How to open VKontakte app with a specific friend?
Asked Answered
W

3

4

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?

Wb answered 20/11, 2014 at 15:45 Comment(0)
G
5

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

Glidden answered 26/11, 2014 at 15:12 Comment(1)
Thank you . It worked. This should be written somewhere in the documentation of VK.Wb
V
4

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>
Vara answered 26/11, 2014 at 19:5 Comment(1)
Nice, but "Roman Truba" answered first, and you didn't provide the answer to the original question. You'll get a +1 though for the effort.Wb
R
0

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)
    }
Rentfree answered 7/10, 2021 at 6:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.