I want to know if there is any way to check if a twitter app is running in the background or not.
Asked
Active
Viewed 332 times
1
-
Can you be a bit more descriptive of what you are trying to accomplish? – Karakuri May 08 '13 at 05:49
-
http://stackoverflow.com/questions/3667022/android-is-application-running-in-background/5862048#5862048. check the link – Raghunandan May 08 '13 at 05:51
-
@Karakuri .In my app I just want to display if there is a twitter app in the phone in which user has already logged into. – Abx May 08 '13 at 05:51
1 Answers
4
You can use the Running Processes:
ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(int i = 0; i < procInfos.size(); i++){
if(procInfos.get(i).processName.equals("com.twitter.android")) {
Toast.makeText(getApplicationContext(), "Twitter is running", Toast.LENGTH_LONG).show();
}
}
I'm not entirely sure why you would want to know this though.
EDIT:
Since you only need to know if it is installed, this code will suit you better:
private boolean isTwitterInstalled() {
PackageManager pm = getPackageManager();
boolean twitter_installed = false;
try {
pm.getPackageInfo("com.twitter.android", PackageManager.GET_ACTIVITIES);
twitter_installed = true;
} catch (PackageManager.NameNotFoundException e) {
twitter_installed = false;
}
return app_installed;
}

Raghav Sood
- 81,899
- 22
- 187
- 195
-
In my app there is a provision for user to log into twitter unless there is a pre twitter app instaled.if there is already a twitter app instaled then the user doesnt need to use the provision of my app, the native app will be used. – Abx May 08 '13 at 05:55
-
1@Abhilash See my edit in that case. The second snippet will tell you if it is installed, but not running as well. However, you can't be certain if the user has logged in or not. – Raghav Sood May 08 '13 at 05:59
-
unfortunately this relies on knowing the Twitter app's package name and only works if they have the official Twitter app. – Karakuri May 08 '13 at 06:01
-
@Karakuri Yes, but that's about as good as it gets. There's thousands of twitter clients out there, and more are added everyday. You can't really keep track of them. A better solution would be to simply ask the user if they have a twitter client installed. – Raghav Sood May 08 '13 at 06:04
-