【问题标题】:How do I make a link open an Instagram page in an app installed on android?如何在安卓上安装的应用程序中创建链接打开 Instagram 页面?
【发布时间】:2015-03-25 07:43:41
【问题描述】:

如果应用程序安装在智能手机上,我需要知道如何让链接打开应用程序中的 Instagram 页面。

www.instagram.com/example 这样的简单方式通过浏览器将您链接到页面,这不是我想要的。

我如何做到这一点?

【问题讨论】:

    标签: android hyperlink


    【解决方案1】:

    试试这个:

    工作 100% <a href="instagram://user?username=untitled.tiff">untitled.tiff</a>

    【讨论】:

    • 这行得通!它询问“在应用程序中打开?”,然后在本机 Instagram 应用程序中打开它。
    • 这对我有用。请问你是怎么知道这个网址的?
    • 只有在安装了 Instagram 应用后才能使用。
    【解决方案2】:

    从浏览器启动 Instagram。 要以链接形式启动 instagram,只需提供如下链接即可:

    <a href="http://instagram.com/p/<picture id>">look at this instagram picture</a>
    

    示例:look at this instagram picture

    <a href="http://instagram.com/p/0nUyKnMJw4">look at this instagram picture</a>
    

    尝试在安卓设备上打开该链接。另外,请记住必须在设备上安装 Instagram。 对于用户,将“p”替换为“_u”,将图片 id 替换为用户名。

    为什么会这样? instagram 应用程序有一个用于 http 和 https 浏览的意图监听器

    <data android:host="instagram.com" android:pathPrefix="/p/" android:scheme="http"/>
    <data android:host="instagram.com" android:pathPrefix="/p/" android:scheme="https"/>
    <data android:host="instagram.com" android:pathPrefix="/_u/" android:scheme="http"/>
    <data android:host="instagram.com" android:pathPrefix="/_u/" android:scheme="https"/>
    <data android:host="instagram.com" android:pathPrefix="/_uid/" android:scheme="http"/>
    <data android:host="instagram.com" android:pathPrefix="/_uid/" android:scheme="https"/>
    <data android:host="instagram.com" android:pathPrefix="/_n/" android:scheme="http"/>
    <data android:host="instagram.com" android:pathPrefix="/_n/" android:scheme="https"/>
    

    编辑:看来我有一个旧的 Manifest 文件。

    【讨论】:

    • 不幸的是它对我来说完全不清楚!我该怎么办??!
    • 我应该复制并粘贴到某个地方吗??
    • 啊,您希望从您的网络浏览器中启动一项活动。
    • 使用www.instagram.com/_u/example 代替www.instagram.com/example。你的意图看起来像这样startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.instagram.com/_u/example/")));
    • @AbhinavUpadhyay 这正是我的回答。你的意思是对他的问题发表评论吗?另请注意,他试图从 Web 浏览器/网页而不是其他应用程序打开应用程序。
    【解决方案3】:

    它对我有用。

    try {
        // mediaLink is something like "https://instagram.com/p/6GgFE9JKzm/" or 
        // "https://instagram.com/_u/sembozdemir"
        Uri uri = Uri.parse(mediaLink);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    
        intent.setPackage("com.instagram.android");
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
            Log.e(TAG, e.getMessage());
    }
    

    【讨论】:

    • 你将如何为 iOS 做同样的事情?
    • 你应该搜索它。当我用谷歌搜索它时,我为你找到了这个。 stackoverflow.com/a/16370613/4557274
    • 这仅适用于用户名。但我找到了。无论如何谢谢:)
    • 如何在 PHP 中做到这一点?
    【解决方案4】:

    您可以通过浏览器锚链接上的 android 意图打开。您可以获取详细信息here

    <a href="intent://instagram.com/#Intent;package=com.instagram.android;scheme=https;end">Open Instagram</a>
    

    【讨论】:

      【解决方案5】:

      我认为您最好的选择是使用 Intent,您可以使用 Intent 发送数据,使用 Intent(短意图)“广播”消息,并且正在监听它的应用程序会响应。

      将其视为我发送给我的一群朋友的电子邮件,如果我要求 mark 做某事,mark 会回复,但其他人会忽略该电子邮件。

      您可以使用此代码发送意图(此代码特定于您的问题,但可以轻松编辑以满足其他需求):

      Intent insta_intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
      insta_intent.setComponent(new ComponentName("com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
      
      //use this if you want to open an image
      insta_intent.setData(Uri.parse("http://instagram.com/p/gjfLqSBQTJ/"));
      
      //And if you want to open a user's profile use this
      insta_intent.setData(Uri.parse("http://instagram.com/_u/USER"));
      
      startActivity(insta_intent);
      

      【讨论】:

      • 马丁?我不是程序员专家,请直接给我一个打开 instagram.com/foodiq 的链接,该链接将我链接到此页面,但通过应用程序,而不是通过浏览器。
      • 啊,你只是想要一个链接来点击/放置一个可以打开应用程序的网站?
      • 这个链接对我有用(注意,在谷歌浏览器的搜索栏中输入时它不起作用):“instagram.com/_u/foodiq”截图:link
      • 有些手机会询问如何打开链接,(通过应用程序、chrome 或...)就像您发送的屏幕截图一样,但像我这样的手机不会,这种方式不会被授权人打开通过应用程序。这是个问题。
      【解决方案6】:

      你可以试试这个方法。您可以通过 Instagram 或浏览器让 POPUP 选择打开链接。 (此方法用于您想要的任何链接,而不仅仅是 Instagram。)

      ***.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
      String url = "Your URL";
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(Uri.parse(url));
      startActivity(intent);
      }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多