is Spotify Running - Android App

Android examples for App:Popular App

Description

is Spotify Running

Demo Code


import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import java.util.List;

public class Main{
    private static final String SPOTIFY_APP_PACKAGE = "com.spotify.music";
    public static boolean isSpotifyRunning(Context context) {
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager
                .getRunningAppProcesses();
        for (int i = 0; i < procInfos.size(); i++) {
            if (procInfos.get(i).processName.equals(SPOTIFY_APP_PACKAGE)) {
                return true;
            }//from   ww  w .  j  a  v  a 2  s . com
        }

        return false;
    }
}

Related Tutorials