Open page in Twitter app from other app - Android

前端 未结 6 1954
南旧
南旧 2020-12-22 20:54

I was looking for some way to launch Twitter app and open a specified page from my application, without webview. I found the solution for Facebook here: Opening facebook app

6条回答
  •  既然无缘
    2020-12-22 21:39

    My answer builds on top of the widely-accepted answers from fg.radigales and Harry. If the user has Twitter installed but disabled (for example by using App Quarantine), this method will not work. The intent for the Twitter app will be selected but it will not be able to process it as it is disabled.

    Instead of:

    getPackageManager().getPackageInfo("com.twitter.android", 0);
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
    

    You can use the following to decide what to do:

    PackageInfo info = getPackageManager().getPackageInfo("com.twitter.android", 0);
    if(info.applicationInfo.enabled)
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
    else
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/wrkoutapp"));
    

提交回复
热议问题