打开Instagram的用户配置文件配置文件、用户、Instagram

2023-09-04 10:00:47 作者:拾七❤

我设法从我的应用程序打开Twitter和Facebook的用户配置文件。但我不能找到 Instagram的的任何引用。 有没有一种方法来打开 Instagram的,以显示像Twitter或Facebook用户资料?

I managed to open the twitter and facebook user profile from my app. But I can not find any references to Instagram. Is There a way to open Instagram in order to show a user profile like in twitter or facebook?

例如,为了获得意图启动Twitter应用程序我做的:

For instance, in order to get the Intent to launch the twitter application I do:

public Intent getOpenTwitterIntent(Context context) {

    try {
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("twitter://user?screen_name="
                        .concat(twitterUsername)));

    } catch (Exception e) {
        return new Intent(
                Intent.ACTION_VIEW,
                Uri.parse("https://twitter.com/#!/".concat(twitterUsername)));
    }

}

我怎么能achive与 Instagram的相似的地方? 先谢谢了。

How can I achive something similar with Instagram? Thanks in advance.

推荐答案

下面是一个方法来获得意图打开Instagram的应用程序到用户的个人资料页:

Here is a method to get the Intent to open the Instagram app to the user's profile page:

/**
 * Intent to open the official Instagram app to the user's profile. If the Instagram app is not
 * installed then the Web Browser will be used.</p>
 * 
 * Example usage:</p> {@code newInstagramProfileIntent(context.getPackageManager(), 
 *     "http://instagram.com/jaredrummler");}</p>
 * 
 * @param pm
 *            The {@link PackageManager}. You can find this class through
 *            {@link Context#getPackageManager()}.
 * @param url
 *            The URL to the user's Instagram profile.
 * @return The intent to open the Instagram app to the user's profile.
 */
public static Intent newInstagramProfileIntent(PackageManager pm, String url) {
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    try {
        if (pm.getPackageInfo("com.instagram.android", 0) != null) {
            if (url.endsWith("/")) {
                url = url.substring(0, url.length() - 1);
            }
            final String username = url.substring(url.lastIndexOf("/") + 1);
            // http://stackoverflow.com/questions/21505941/intent-to-open-instagram-user-profile-on-android
            intent.setData(Uri.parse("http://instagram.com/_u/" + username));
            intent.setPackage("com.instagram.android");
            return intent;
        }
    } catch (NameNotFoundException ignored) {
    }
    intent.setData(Uri.parse(url));
    return intent;
}