【问题标题】:Android Intent to open instagram posting viewAndroid意图打开Instagram发布视图
【发布时间】:2020-09-08 12:07:49
【问题描述】:

如何在发布模式下打开 Instagram 应用程序(所以我们在 Instagram 应用程序的主屏幕上单击加号后获得的视图相同)?我见过这样做的 android 应用程序,但是无法找到解释如何实现它的信息。

该代码适用于打开主视图:

Uri uri = Uri.parse("http://instagram.com/");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
startActivity(likeIng);

也许还有一些其他的 uri 可以工作?

【问题讨论】:

标签: android instagram


【解决方案1】:

经过一番研究后发现,使用“instagram://share”进行深度链接可以打开所需的视图。

【讨论】:

    【解决方案2】:

    只有在 Instagram 上有要分享的媒体时,您才能这样做:

    try {
            String type = "image/*";
            String filename = "/myPhoto.jpg";
            String mediaPath = Environment.getExternalStorageDirectory() + filename;
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setPackage("com.instagram.android");
            share.setType(type);
            File media = new File(mediaPath);
            Uri uri = null;
            share.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(share);
        } catch (Exception e) {
            e.printStackTrace();
        }
    

    你可以创建一个假媒体来使用这个方法。

    【讨论】:

      【解决方案3】:

      只是为了扩展@Paavo 答案以在代码中显示答案。

      Uri uri = Uri.parse("instagram://share");
      Intent intent = new Intent(Intent.ACTION_VIEW, uri);
      intent.setPackage("com.instagram.android");
      
      //Check that the user can open the intent, meaning they have the Instagram app installed
      if (getPackageManager().resolveActivity(intent, 0) != null)
          startActivity(intent);
      else //User doesn't have app installed, handle however you want
          throw new Resources.NotFoundException();
      

      【讨论】:

        猜你喜欢
        • 2013-08-28
        • 1970-01-01
        • 2012-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多