打开Instagram用户个人资料

Bla*_*elt 28 android android-intent instagram

我设法从我的应用程序打开TwitterFacebook用户配置文件.但我找不到任何参考Instagram.

有没有办法打开 Instagram,以显示用户个人资料,如在Twitter或Facebook?

例如,为了Intent启动twitter应用程序我做:

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)));
    }

}
Run Code Online (Sandbox Code Playgroud)

我怎么能得到类似的东西Instagram?提前致谢.

Jar*_*ler 39

这是一种Intent将Instagram应用程序打开到用户个人资料页面的方法:

/**
 * 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;
}
Run Code Online (Sandbox Code Playgroud)

  • 我很高兴您使用了"http://instagram.com/_u/..."`URI.这对我来说在Instagram应用程序中打开一个配置文件(只要它已安装)而不是默认浏览器. (2认同)

小智 9

到目前为止,我找不到直接显示用户个人资料的方法..但是有办法解决..

从GitHub的Instagram Manifest中找到了这个解决方案

 Intent iIntent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");

iIntent.setComponent(new ComponentName( "com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
iIntent.setData( Uri.parse( "http://instagram.com/p/gjfLqSBQTJ/") );

startActivity(iIntent);
Run Code Online (Sandbox Code Playgroud)

这将在应用程序中打开用户的特定图像发布.从页面应用程序用户可以打开包含内部链接的配置文件.

如果你想打开最近的帖子或其他什么,你可以使用Instagram API

这不是我们想要的,但现在更好的选择......我猜:)

  • @ dinesh-balu你的解决方案工作只需要将URL更改为`iIntent.setData(Uri.parse("http://instagram.com/p/gjfLqSBQTJ/"));`到`intent.setData(Uri.parse) ("http://instagram.com/_u/"+ INSTAGRAM_USERNAME));`**URL**http://instagram.com/_u/**[USERNAME]** (8认同)

小智 8

经过简短的搜索并尝试了我们都知道的"不会工作",我得到了这个工作

 Uri uri = Uri.parse("http://instagram.com/mzcoco2you");
 Intent intent = new Intent(Intent.ACTION_VIEW, uri);
 startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

这应该启动你的默认浏览器......你去.答案是"instagram.com"+"/ UserName".

  • 我试过了,它打开浏览器而不是应用程序.有没有办法打开应用程序? (3认同)