Example usage for android.content Context ACTIVITY_SERVICE

List of usage examples for android.content Context ACTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context ACTIVITY_SERVICE.

Prototype

String ACTIVITY_SERVICE

To view the source code for android.content Context ACTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Usage

From source file:edu.rutgers.winlab.crowdpp.ui.HomeFragment.java

private boolean isMyServiceRunning() {
    //final View view = inflater.inflate(R.layout.home_fragment_layout, container, false);   
    ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("edu.rutgers.winlab.crowdpp.service.SpeakerCountService".equals(service.service.getClassName())) {
            return true;

        }/*from ww  w.  j  a va  2s  .  co  m*/
    }
    return false;
}

From source file:net.wequick.small.Small.java

public static void preSetUp(Application context) {
    sContext = context;/*from ww  w.  ja  va  2 s.  com*/

    // Register default bundle launchers
    registerLauncher(new ActivityLauncher());
    registerLauncher(new ApkBundleLauncher());
    registerLauncher(new WebBundleLauncher());

    PackageManager pm = context.getPackageManager();
    String packageName = context.getPackageName();

    // Check if host app is first-installed or upgraded
    int backupHostVersion = getHostVersionCode();
    int currHostVersion = 0;
    try {
        PackageInfo pi = pm.getPackageInfo(packageName, 0);
        currHostVersion = pi.versionCode;
    } catch (PackageManager.NameNotFoundException ignored) {
        // Never reach
    }

    if (backupHostVersion != currHostVersion) {
        sIsNewHostApp = true;
        setHostVersionCode(currHostVersion);
    } else {
        sIsNewHostApp = false;
    }

    // Collect host certificates
    try {
        Signature[] ss = pm.getPackageInfo(Small.getContext().getPackageName(),
                PackageManager.GET_SIGNATURES).signatures;
        if (ss != null) {
            int N = ss.length;
            sHostCertificates = new byte[N][];
            for (int i = 0; i < N; i++) {
                sHostCertificates[i] = ss[i].toByteArray();
            }
        }
    } catch (PackageManager.NameNotFoundException ignored) {

    }

    // Check if application is started after unexpected exit (killed in background etc.)
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName launchingComponent = am.getRunningTasks(1).get(0).topActivity;
    ComponentName launcherComponent = pm.getLaunchIntentForPackage(packageName).getComponent();
    if (!launchingComponent.equals(launcherComponent)) {
        // In this case, system launching the last restored activity instead of our launcher
        // activity. Call `setUp' synchronously to ensure `Small' available.
        setUp(context, null);
    }
}

From source file:com.digipom.manteresting.android.service.cache.CacheService.java

@Override
public void onCreate() {
    if (LoggerConfig.canLog(Log.VERBOSE)) {
        Log.v(TAG, "onCreate()");
    }//from   w  ww.j  a  v a 2  s  .c o m

    final int memoryClass = tryGetLargeMemoryClass(
            ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)));

    imageDownloader = new ImageDownloader();

    // 25% of memory allocated to the bitmap memory cache
    bitmapMemoryCache = new BitmapMemoryCache((memoryClass * 1024 * 1024) / 4);

    // 12% of memory allocated to the image memory cache
    imageMemoryCache = new LruCache<String, ImageWithCategory>((memoryClass * 1024 * 1024) / 8) {
        @Override
        protected int sizeOf(String key, ImageWithCategory value) {
            return value != null && value.image != null ? value.image.length : 0;
        }
    };

    initializePrimaryFileCache();
    initializeSecondaryFileCache();
}

From source file:com.vonglasow.michael.satstat.GpsEventReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);

    // some logic to use the pre-1.7 setting KEY_PREF_UPDATE_WIFI as a
    // fallback if KEY_PREF_UPDATE_NETWORKS is not set
    Set<String> fallbackUpdateNetworks = new HashSet<String>();
    if (sharedPref.getBoolean(Const.KEY_PREF_UPDATE_WIFI, false)) {
        fallbackUpdateNetworks.add(Const.KEY_PREF_UPDATE_NETWORKS_WIFI);
    }//  w  ww.  j  a  va  2s.c om
    Set<String> updateNetworks = sharedPref.getStringSet(Const.KEY_PREF_UPDATE_NETWORKS,
            fallbackUpdateNetworks);

    if (intent.getAction().equals(Const.GPS_ENABLED_CHANGE)
            || intent.getAction().equals(Const.GPS_ENABLED_CHANGE)) {
        //FIXME: why are we checking for the same intent twice? Should on of them be GPS_FIX_CHANGE?
        // an application has connected to GPS or disconnected from it, check if notification needs updating
        boolean notifyFix = sharedPref.getBoolean(Const.KEY_PREF_NOTIFY_FIX, false);
        boolean notifySearch = sharedPref.getBoolean(Const.KEY_PREF_NOTIFY_SEARCH, false);
        if (notifyFix || notifySearch) {
            boolean isRunning = false;
            ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
                if (PasvLocListenerService.class.getName().equals(service.service.getClassName())) {
                    isRunning = true;
                }
            }
            if (!isRunning) {
                Intent startServiceIntent = new Intent(context, PasvLocListenerService.class);
                startServiceIntent.setAction(intent.getAction());
                startServiceIntent.putExtras(intent.getExtras());
                context.startService(startServiceIntent);
            }
        }
    } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)
            && updateNetworks.contains(Const.KEY_PREF_UPDATE_NETWORKS_WIFI)) {
        // change in WiFi connectivity, check if we are connected and need to refresh AGPS
        //FIXME: KEY_PREF_UPDATE_WIFI as fallback only
        NetworkInfo netinfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (netinfo == null)
            return;
        if (!netinfo.isConnected())
            return;
        //Toast.makeText(context, "WiFi is connected", Toast.LENGTH_SHORT).show();
        Log.i(this.getClass().getSimpleName(), "WiFi is connected");
        refreshAgps(context, true, false);
    } else if ((intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION))
            || (intent.getAction().equals(Const.AGPS_DATA_EXPIRED))) {
        // change in network connectivity or AGPS expiration timer fired
        boolean isAgpsExpired = false;
        if (intent.getAction().equals(Const.AGPS_DATA_EXPIRED)) {
            Log.i(this.getClass().getSimpleName(), "AGPS data expired, checking available networks");
            isAgpsExpired = true;
        }
        NetworkInfo netinfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
                .getActiveNetworkInfo();
        if (netinfo == null)
            return;
        if (!netinfo.isConnected())
            return;
        String type;
        if ((netinfo.getType() < ConnectivityManager.TYPE_MOBILE_MMS)
                || (netinfo.getType() > ConnectivityManager.TYPE_MOBILE_HIPRI)) {
            type = Integer.toString(netinfo.getType());
        } else {
            // specific mobile data connections will be treated as TYPE_MOBILE
            type = Const.KEY_PREF_UPDATE_NETWORKS_MOBILE;
        }
        if (!updateNetworks.contains(type))
            return;
        if (!isAgpsExpired)
            Log.i(this.getClass().getSimpleName(),
                    "Network of type " + netinfo.getTypeName() + " is connected");
        // Enforce the update interval if we were called by a network event
        // but not if we were called by a timer, because in that case the
        // check has already been done. (I am somewhat paranoid and don't
        // count on alarms not going off a few milliseconds too early.)
        refreshAgps(context, !isAgpsExpired, false);
    }
}

From source file:com.nick.scalpel.core.AutoFoundWirer.java

private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme,
        Field field, Object forWho) {
    Resources resources = context.getResources();
    switch (type) {
    case STRING://  w w w. ja v  a  2 s  .c o m
        setField(field, forWho, resources.getString(idRes));
        break;
    case COLOR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, resources.getColor(idRes, theme));
        } else {
            //noinspection deprecation
            setField(field, forWho, resources.getColor(idRes));
        }
        break;
    case INTEGER:
        setField(field, forWho, resources.getInteger(idRes));
        break;
    case BOOL:
        setField(field, forWho, resources.getBoolean(idRes));
        break;
    case STRING_ARRAY:
        setField(field, forWho, resources.getStringArray(idRes));
        break;
    case INT_ARRAY:
        setField(field, forWho, resources.getIntArray(idRes));
        break;
    case PM:
        setField(field, forWho, context.getSystemService(Context.POWER_SERVICE));
        break;
    case ACCOUNT:
        setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE));
        break;
    case ALARM:
        setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE));
        break;
    case AM:
        setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE));
        break;
    case WM:
        setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE));
        break;
    case NM:
        setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE));
        break;
    case TM:
        setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE));
        break;
    case TCM:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE));
        }
        break;
    case SP:
        setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context));
        break;
    case PKM:
        setField(field, forWho, context.getPackageManager());
        break;
    case HANDLE:
        setField(field, forWho, new Handler(Looper.getMainLooper()));
        break;
    case ASM:
        setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE));
        break;
    case CAP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE));
        }
        break;
    case KGD:
        setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE));
        break;
    case LOCATION:
        setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE));
        break;
    case SEARCH:
        setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE));
        break;
    case SENSOR:
        setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE));
        break;
    case STORAGE:
        setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE));
        break;
    case WALLPAPER:
        setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE));
        break;
    case VIBRATOR:
        setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE));
        break;
    case CONNECT:
        setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE));
        break;
    case NETWORK_STATUS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE));
        }
        break;
    case WIFI:
        setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE));
        break;
    case AUDIO:
        setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE));
        break;
    case FP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE));
        }
        break;
    case MEDIA_ROUTER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE));
        }
        break;
    case SUB:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
        }
        break;
    case IME:
        setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE));
        break;
    case CLIP_BOARD:
        setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE));
        break;
    case APP_WIDGET:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE));
        }
        break;
    case DEVICE_POLICY:
        setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE));
        break;
    case DOWNLOAD:
        setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE));
        break;
    case BATTERY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE));
        }
        break;
    case NFC:
        setField(field, forWho, context.getSystemService(Context.NFC_SERVICE));
        break;
    case DISPLAY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE));
        }
        break;
    case USER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.USER_SERVICE));
        }
        break;
    case APP_OPS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE));
        }
        break;
    case BITMAP:
        setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null));
        break;
    }
}

From source file:com.shivshankar.MyFirebaseMessagingService.java

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Log.d("TAGRK", "From: " + remoteMessage.getFrom());
    String message = "", title = "", strImageURL = "";
    if (remoteMessage.getData() != null && remoteMessage.getData().size() > 0) {
        Log.d("TAGRK", "Message data payload: " + remoteMessage.getData());

        message = "" + remoteMessage.getData().get(Config.MESSAGE_KEY);
        title = "" + remoteMessage.getData().get(Config.TITLE_KEY);
        strImageURL = "" + remoteMessage.getData().get(Config.IMAGE_KEY);
    } else if (remoteMessage.getNotification() != null) {
        Log.d("TAGRK", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        message = "" + remoteMessage.getNotification().getBody();
        title = "" + remoteMessage.getNotification().getTitle();
        strImageURL = "" + remoteMessage.getNotification().getIcon();
    }//from  w  w w  .ja  va  2  s.  c  o  m

    if (strImageURL != null && !strImageURL.equals("") && !strImageURL.equals("null")) {
        Handler handler = new Handler(Looper.getMainLooper());
        final String finalTitle = title;
        final String finalMessage = message;
        final String finalStrImageURL = strImageURL;
        handler.post(new Runnable() {
            public void run() {
                new ServerAPICallImageBitmap(finalTitle, finalMessage, finalStrImageURL, "").execute();
            }
        });
    } else if (title.equalsIgnoreCase("Logout")) {
        try {
            SharedPreferences.Editor editor = AppPreferences.getPrefs().edit();
            editor.putString(commonVariables.KEY_LOGIN_ID, "0");
            editor.putBoolean(commonVariables.KEY_IS_LOG_IN, false);
            editor.putString(commonVariables.KEY_SELLER_PROFILE, "");
            editor.putString(commonVariables.KEY_BUYER_PROFILE, "");
            editor.putString(commonVariables.KEY_BRAND, "");
            editor.putBoolean(commonVariables.KEY_IS_BRAND, false);
            editor.putBoolean(commonVariables.KEY_IS_SELLER, false);
            editor.putBoolean(commonVariables.KEY_IS_SKIPPED_LOGIN_BUYER, false);
            editor.commit();
            android.os.Process.killProcess(android.os.Process.myPid());
            List<ApplicationInfo> packages;
            PackageManager pm;
            pm = getPackageManager();
            packages = pm.getInstalledApplications(0);

            ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            String myPackage = getApplicationContext().getPackageName();
            for (ApplicationInfo packageInfo : packages) {
                if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
                    continue;
                if (packageInfo.packageName.equals(myPackage))
                    continue;
                mActivityManager.killBackgroundProcesses(packageInfo.packageName);
            }
            mActivityManager.restartPackage(myPackage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else
        sendNotification(title, message);
    Log.i("TAGRK", "Received: " + remoteMessage.toString());
}

From source file:com.google.transporttracker.TrackerActivity.java

private boolean isServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }/*  ww  w.  java2 s .  co  m*/
    }
    return false;
}

From source file:com.simas.vc.background_tasks.FFmpegService.java

private boolean isRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (getClass().getName().equals(service.service.getClassName())) {
            return true;
        }//from  www .j  av a 2  s.c  o m
    }
    return false;
}

From source file:com.app.sniffy.MainActivity.java

private boolean isMyServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (SentBoxService.class.getName().equals(service.service.getClassName())) {
            return true;
        }/*from  w  w w  .  j a  va2s.  co m*/
    }
    return false;
}

From source file:com.ape.transfer.util.FileIconLoader.java

/**
 * Constructor./*  w  ww .  java2s  .c o  m*/
 *
 * @param context content context
 */
public FileIconLoader(Context context) {
    mContext = context;
    final ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE));
    final float cacheSizeAdjustment = (am.isLowRamDevice()) ? 0.5f : 1.0f;
    final int holderCacheSize = (int) (cacheSizeAdjustment * HOLDER_CACHE_SIZE);
    mImageCache = new LruCache<Object, ImageHolder>(holderCacheSize);
    mThumbnailSize = context.getResources().getDimensionPixelSize(R.dimen.icon_width_height);
}