Launch Twitter App

Possible duplicate:
Android intention for Twitter application

I want to go to the page from my Android application and want it to be done by running my own Twitter application.

How can I do this, and also if the Twitter client does not exist on the user's mobile phone, he must go to the twitter mobile website.

+6
source share
4 answers

To check if Intent exists, follow these steps:

public static boolean isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; } 

( source )

For twitter check this snippet:

 Intent tweetIntent = new Intent(Intent.ACTION_SEND); tweetIntent.putExtra(Intent.EXTRA_TEXT, "Test tweet"); tweetIntent.setType("application/twitter"); 

( source )

+5
source

Since the last version of the Twitter app 3.0.0 on December 9, 2011, the official Twitter app has maintained a regular intent mechanism. All you have to do is use regular browser intent, in case it is a valid twitter address, the official application is registered as one of the resolvers of this intention.

... just copy and paste the goBeepit dev comment, because it works for me, android asks you to open in a browser or Twitter application that I use it just that

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/norman784")); startActivity(intent); 
+5
source

From my testing, I could not find a good way to do this and instead resorted to a solution that is not necessarily β€œbest practice”. It only works with the official Twitter app and not with others. This solution will not succeed if the official application changes the internal API. Therefore, please use this solution with caution and be aware of its limitations.

This code is not written correctly, but it works. My advice is to change it so as not to use so many resources.

The code checks if the Twitter application is installed. If so, the Twitter application launches; otherwise, the browser starts.

Twitter has the name Twitter (also the name screen_name) and twitter id: they do not match.

 //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<ResolveInfo> 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 && packageName.equals("com.twitter.android")) { try { String formattedTwitterAddress = "twitter://user/" ; Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress)); long twitterId = <Here is the place for the twitter id> 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 = <Put the twitter name here> String formattedTwitterAddress = "http://twitter.com/" + twitterName; Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress)); startActivity(browseTwitter); } catch (Exception e) { } 
+4
source

List all packages that respond to ACTION_SEND and filter them on the most popular Twitter clients. http://regis.decamps.info/blog/2011/06/intent-to-open-twitter-client-on-android/

+2
source

Source: https://habr.com/ru/post/885506/


All Articles