Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From my testing, I couldn't find a nice way to do this, and instead resorted to a solution that is not necessarily 'best practice'. It works only with the official twitter app and not with the others. This solution will fail if the official app changes its internal API. Therefore, please use this solution with caution and know its limitations.</p> <p>This code is not written in a good way, but it does work. My advice is to change it to not use so many resources.</p> <p>The code checks to see whether the Twitter app is installed. If so, the Twitter app is launched; otherwise, the browser is launched.</p> <p>Twitter has twitter name (also named screen_name) and twitter id: they are not the same.</p> <pre><code>//Checking If the app is installed, according to the package name Intent intent = new Intent(); intent.setType("text/plain"); intent.setAction(Intent.ACTION_SEND); final PackageManager packageManager = getPackageManager(); List&lt;ResolveInfo&gt; list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : list) { String packageName = resolveInfo.activityInfo.packageName; //In case that the app is installed, lunch it. if (packageName != null &amp;&amp; packageName.equals("com.twitter.android")) { try { String formattedTwitterAddress = "twitter://user/" ; Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress)); long twitterId = &lt;Here is the place for the twitter id&gt; browseTwitter.putExtra("user_id", twitterId); startActivity(browseTwitter); return; } catch (Exception e) { } } } //If it gets here it means that the twitter app is not installed. Therefor, lunch the browser. try { String twitterName = &lt;Put the twitter name here&gt; String formattedTwitterAddress = "http://twitter.com/" + twitterName; Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress)); startActivity(browseTwitter); } catch (Exception e) { } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload