Check if user is following on Twitter

In my application, the user is allowed to do something by clicking a button. I am using the following code:

boolean found = false; Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "Blah blah"); final PackageManager pm = getPackageManager(); final List<?> activityList = pm.queryIntentActivities(intent, 0); int len = activityList.size(); for (int i = 0; i < len; i++) { final ResolveInfo app = (ResolveInfo) activityList.get(i); if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) { found = true; intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity"); startActivity(intent); break; } } if(!found) showDialog(NO_APP); 

The code works fine, but I want to add a function to it. When the user does not log in to Twitter, I want to display a message stating that he is not logged in. The code, right now, just directs the user to the Twitter login page. How can I disable this and get the desired result? Thanks!!

+4
source share
1 answer

To do this, you can first check that you have twitterToken and twitterTokenSecret.

Try this .may method, it helps :)

 if(twitterToken!=null && twitterTokenSecret!=null && twitterToken.length()>0 && twitterTokenSecret.length()>0){ //do your work }else{ //show alert dialog } 
+1
source

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


All Articles