How to do this: For example, there is an inscription: "We are in VKontakte" and "We are in facebook", when you click on "We are in VKontakte", the application immediately offers to open the link with the VC application (of course if it is installed on the phone), similarly to "We are in facebook"
1 answer
We create an intent as for opening a regular link. If you just need to offer to open them, then do nothing, it will be in the list of applications. If you first need to open them, then we search among the applications with which you can open this link, suitable and set it.
private static final String VK_APP_PACKAGE_ID = "com.vkontakte.android"; private static final String FACEBOOK_APP_PACKAGE_ID = "com.facebook.katana"; public static void openLink(Activity activity, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); List<ResolveInfo> resInfo = activity.getPackageManager().queryIntentActivities(intent, 0); if (resInfo.isEmpty()) return; for (ResolveInfo info: resInfo) { if (info.activityInfo == null) continue; if (VK_APP_PACKAGE_ID.equals(info.activityInfo.packageName) || FACEBOOK_APP_PACKAGE_ID.equals(info.activityInfo.packageName) ) { intent.setPackage(info.activityInfo.packageName); break; } } activity.startActivity(intent); } Иcпользоваение в активности: openLink(this, "http://vk.com/id1"); openLink(this, "https://www.facebook.com/groups/StackOverFlow"); - Maybe you know how to post a photo on the wall in PB and VK with the help of intents? - Pax Beach
|