somewhat hackish method of determining if Google Maps is in the foreground. - Android Map

Android examples for Map:Google Map

Description

somewhat hackish method of determining if Google Maps is in the foreground.

Demo Code


//package com.java2s;
import android.app.ActivityManager;

import android.content.Context;

import java.util.List;

public class Main {
    private static final String MAPS_PACKAGE = "com.google.android.apps.maps";

    /**/*from   ww  w. j  a v  a  2s . c  o  m*/
     * somewhat hackish method of determining if Google Maps is in the foreground.
     * What we really want to do is detect if navigation is enabled but there is no API for that.
     *
     * @param context
     * @return
     */
    public static boolean isMapsInForeground(Context context) {
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> services = activityManager
                .getRunningTasks(Integer.MAX_VALUE);
        return MAPS_PACKAGE.equals(services.get(0).topActivity
                .getPackageName());
    }
}

Related Tutorials