Created
September 11, 2016 17:54
-
-
Save truedem/804401024f470c9749b9ba240092748a to your computer and use it in GitHub Desktop.
Check if an app is running in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // packageName = "com.example.yourapp" | |
| public Boolean isAppRunning(String packageName) { | |
| ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); // this = context | |
| List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses(); | |
| for(int i = 0; i < procInfos.size(); i++) { | |
| if(procInfos.get(i).processName.equals(packageName)) { | |
| // Toast.makeText(getApplicationContext(), "App " + packageName + " is running", Toast.LENGTH_LONG).show(); | |
| return true; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment