【问题标题】:Launch Twitter app from another app in Android从 Android 中的另一个应用程序启动 Twitter 应用程序
【发布时间】:2018-07-11 01:55:41
【问题描述】:

我正在尝试从我在 Android 上的 Cordova 应用程序启动 Twitter 应用程序,但它总是在应用程序浏览器中打开,我在 IOS 上使用相同的代码并且它运行良好。 这是我正在使用的代码:

window.open('twitter://user?screen_name=MyTwitterUserName', '_system'); 

在执行上述代码之前,我检查是否已经安装了 Twitter 应用程序,我已经在手机上安装了它,但仍然在浏览器中打开它,我之前说的代码在 IOS 上没有任何问题,我也试过这个代码,但它们都不能在 Android 上运行。

window.open('twitter://user?user_id=MyTwitterID', '_system');

【问题讨论】:

    标签: android cordova twitter


    【解决方案1】:

    这应该会启动 Twitter 应用程序。

    Intent intent = null;
    try {
        // get the Twitter app if possible
        this.getPackageManager().getPackageInfo("com.twitter.android", 0);
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } catch (Exception e) {
        // no Twitter app, revert to browser
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERID_OR_PROFILENAME"));
    }
    this.startActivity(intent);
    

    也试试这个插件:https://github.com/lampaa/com.lampa.startapp

    【讨论】:

    • 谢谢,但我使用的是 Cordova,twitter://user?user_id=USERID 对我不起作用
    • 我没有使用任何插件。它像普通链接一样打开,对于 facebook 'fb://profile/name' 对于 youtube vnd.youtube://www.youtube.com/channel,除了 Twitter,它们都可以正常工作,Twitter 在 IOS 上可以正常工作,但不能在 Android 上运行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    相关资源
    最近更新 更多