【问题标题】:Open Instagram User Profile打开 Instagram 用户资料
【发布时间】:2013-03-19 10:44:44
【问题描述】:

我设法从我的应用程序中打开了 TwitterFacebook 用户配置文件。但我找不到任何对Instagram 的引用。

有没有办法打开 Instagram 以便在 twitter 或 facebook 中显示用户个人资料?

例如,为了让Intent 启动我所做的推特应用程序:

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

}

我怎样才能获得与Instagram 类似的东西? 提前致谢。

【问题讨论】:

  • 以上问题你有解决办法吗?
  • 不,我没有。对不起
  • okie np...感谢您的回复...如果您有任何问题请留言...
  • 对于寻找 URI 以在 instagram 应用程序中打开特定个人资料的任何人,我发现这个答案对我来说很好:stackoverflow.com/a/23511180/3131147
  • @McAdam331,它会打开原生应用吗?

标签: android android-intent instagram


【解决方案1】:

以下是获取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;
}

【讨论】:

  • 很高兴您使用了"http://instagram.com/_u/..." URI。这对我来说可以在 Instagram 应用程序中打开个人资料(只要它已安装)而不是默认浏览器。
【解决方案2】:

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

Instagram Manifest from GitHub找到这个解决方案

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

这将打开用户在应用中发布的特定图片。用户可以从页面应用程序中打开带有链接的个人资料。

如果你想打开最近的帖子什么的,你可以使用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 instagram.com/_u [USERNAME]
  • 只有在账户公开的情况下才有效。例如。首先获取媒体链接,例如instagram.com/p/xxxXXxxx,但从您自己的公共帐户中获取,然后将您的帐户设为私有并尝试启动此代码。而且它不会起作用。取而代之的是媒体,您将看到空白的 Instagram 应用页面。
【解决方案3】:

经过简短的搜索并尝试了我们都知道的“WON'T WORK”后,我得到了这个工作

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

这应该会启动您的默认浏览器,然后...就可以了。答案是“instagram.com”+“/UserName”。

【讨论】:

【解决方案4】:

直接打开 Instagram 应用到用户个人资料:

String scheme = "http://instagram.com/_u/USER";
String path = "https://instagram.com/USER";
String nomPackageInfo ="com.instagram.android";
    try {
        activite.getPackageManager().getPackageInfo(nomPackageInfo, 0);
        intentAiguilleur = new Intent(Intent.ACTION_VIEW, Uri.parse(scheme));
        } catch (Exception e) {
            intentAiguilleur = new Intent(Intent.ACTION_VIEW, Uri.parse(path));
        }
        activite.startActivity(intentAiguilleur); 

// Use this link to open directly a picture
  String scheme = "http://instagram.com/_p/PICTURE";

【讨论】:

  • 感谢您的贡献。
【解决方案5】:
try {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://instagram.com/_u/" + "username"));
    intent.setPackage("com.instagram.android");
    startActivity(intent);
    } 
  catch (android.content.ActivityNotFoundException anfe) 
     {
       startActivity(new Intent(Intent.ACTION_VIEW,
       Uri.parse("https://www.instagram.com/" + username)));
     }

【讨论】:

    【解决方案6】:

    很遗憾,目前您无法打开 Instagram 应用程序以直接转到用户个人资料。但是,您可以在 Instagram 应用中打开某张照片。

    我提供的以下代码将在 Instagram 应用程序中打开某张照片。如果没有安装 Instagram 应用,它会在浏览器中打开用户个人资料。

    public void openInstagram (View view) {
        Intent intent = null;
        String pictureId = "p/0vtNxgqHx9";
        String pageName = "d4v3_r34d";
        try {intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
            intent.setComponent(new ComponentName("com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
            intent.setData(Uri.parse("http://instagram.com/" + pictureId));
        } catch (Exception e) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://instagram.com/" + pageName));
        }
        this.startActivity(intent);
    

    我使您可以很容易地编辑此代码以用于您自己的目的。将“String pictureId”设置为您要显示的图片的 id,并将“String pageName”设置为您 Instagram 帐户的用户名。

    用户名部分很明显,但如果您需要帮助以获取图片 ID,请查看此picture

    【讨论】:

      【解决方案7】:

      检查下面的代码:

      Intent instaintent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
      instaintent.setData(Uri.parse("https://www.instagram.com/insta_save_new/"));    
      startActivity(instaintent);
      

      【讨论】:

        猜你喜欢
        • 2014-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-15
        • 1970-01-01
        • 2020-07-10
        • 2013-10-11
        • 1970-01-01
        相关资源
        最近更新 更多