问题
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?
回答1:
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
回答2:
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>
来源:https://stackoverflow.com/questions/27043676/how-to-open-vkontakte-app-with-a-specific-friend