【问题标题】:Open Vine profile from Android app从 Android 应用打开 Vine 个人资料
【发布时间】:2013-06-13 17:54:30
【问题描述】:

我正在尝试通过代码将 Vine (https://vine.co/) Android 应用程序打开到特定的个人资料页面。我一直在尝试通常的方法,通过 URI 没有运气。这是我当前的非功能代码:

public void vineButtonClicked(View view)
{
    Intent vineIntent = getVineIntent(view.getContext(), VINE_PROFILE_ID);

    try {
        startActivity(vineIntent);          
    } catch(Exception e) {
        // getVineIntent() doesn't fail on returning a new intent with 
        // the vine:// URI, so this catches the failed intent.  Why 
        // doesn't getVineIntent fail?
        Toast.makeText(view.getContext(), "Vine is not installed!", Toast.LENGTH_SHORT).show();
    }
}

public Intent getVineIntent(Context context, String userProfile) {
    try {
         return new Intent(Intent.ACTION_VIEW,
                 Uri.parse("vine://user/".concat(userProfile)));
    } catch (Exception e) {
        return getWebViewIntent("http://vine.co");
    }
}

我尝试将 vine:// 换成 twitter:// URI 方案,它按预期工作。我怎样才能做到这一点?

【问题讨论】:

    标签: android android-intent uri vine


    【解决方案1】:

    这样的事情就可以了:

    String vineUrl = "https://vine.co/u/<PAGE_ID>";
    Intent vineIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(vineUrl));
    vineIntent.setPackage("co.vine.android");
    
    try {
        startActivity(vineIntent);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(vineUrl)));
    }
    

    【讨论】:

      【解决方案2】:

      为什么 getVineIntent 不会失败?

      为什么会这样?你所做的只是构建一个Intent

      我怎样才能做到这一点?

      在 Vine 找到一份工作,并在某些应用中添加对 vine:// Uri 值的支持。显然,您没有响应此类Uri 的应用程序,我假设您的设备上已经安装了一些 Vine 客户端。

      【讨论】:

      • 哦,我不知道为什么我认为创建带有损坏 URI 的 Intent 会失败。那么除了 Vine 将这个方案添加到他们的清单之外,没有其他方法可以完成这项任务吗?他们会在他们的 iOS 版本而不是 Android 版本中包含这个似乎很奇怪。
      • @karl_:“我不知道为什么我认为创建带有损坏 URI 的 Intent 会失败”——任何没有匹配活动的 startActivity() 调用都会失败,并显示ActivityNotFoundException。 “他们会在他们的 iOS 版本而不是 Android 版本中包含这个似乎很奇怪”——并不是每个人都会同步更新他们的应用程序。除此之外,你还得问 Vine。
      • 哦,好吧。感谢您的快速回答。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 2014-02-25
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多