List of usage examples for android.content Context ACTIVITY_SERVICE
String ACTIVITY_SERVICE
To view the source code for android.content Context ACTIVITY_SERVICE.
Click Source Link
From source file:com.bukanir.android.utils.Utils.java
public static boolean isHttpServiceRunning(Context context) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (BukanirHttpService.class.getName().equals(service.service.getClassName())) { return true; }/*from w w w .j a v a2 s .c om*/ } return false; }
From source file:fr.inria.ucn.collectors.RunningAppsCollector.java
@SuppressLint("NewApi") @Override/* w w w . j a va2 s .c o m*/ public void run(Context c, long ts) { try { ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); PackageManager pm = c.getPackageManager(); JSONObject data = new JSONObject(); // running tasks JSONArray runTaskArray = new JSONArray(); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(50); boolean first = true; for (ActivityManager.RunningTaskInfo info : taskInfo) { JSONObject jinfo = new JSONObject(); jinfo.put("task_id", info.id); jinfo.put("task_num_activities", info.numActivities); jinfo.put("task_num_running", info.numRunning); // is this the foreground process ? jinfo.put("task_foreground", first); if (first) { first = false; } if (info.topActivity != null) { jinfo.put("task_top_class_name", info.topActivity.getClassName()); jinfo.put("task_top_package_name", info.topActivity.getPackageName()); try { // map package name to app label CharSequence appLabel = pm.getApplicationLabel(pm.getApplicationInfo( info.topActivity.getPackageName(), PackageManager.GET_META_DATA)); jinfo.put("task_app_label", appLabel.toString()); } catch (NameNotFoundException e) { } } runTaskArray.put(jinfo); } data.put("runningTasks", runTaskArray); // processes JSONArray runProcArray = new JSONArray(); for (ActivityManager.RunningAppProcessInfo pinfo : am.getRunningAppProcesses()) { JSONObject jinfo = new JSONObject(); jinfo.put("proc_uid", pinfo.uid); jinfo.put("proc_name", pinfo.processName); jinfo.put("proc_packages", Helpers.getPackagesForUid(c, pinfo.uid)); runProcArray.put(jinfo); } data.put("runningAppProcesses", runProcArray); // done Helpers.sendResultObj(c, "running_apps", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json obj", jex); } }
From source file:tm.android.chronos.services.TimerRunner.java
private void setActivityState() { //Log.i("Timer Service", "Entering setActivityState at " + ftime.format(System.currentTimeMillis())); int importance = 230; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo appProcessInfo : activityManager.getRunningAppProcesses()) for (String pkg : appProcessInfo.pkgList) if (pkg.equals(context.getPackageName())) importance = appProcessInfo.importance; // only this value ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND say that the application is visible on the foreground launchNotification = importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; }
From source file:org.videolan.myvlc.tool.BitmapCache.java
private BitmapCache() { // Get the global context of the application Context context = MyVLCApp.getAppContext(); final int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass();//from w ww. j a va 2s. c o m // Use 1/5th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 5; Log.d(TAG, "LRUCache size sets to " + cacheSize); mMemCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:com.alivenet.dmvtaxi.FcmUtil.MyGcmListenerService.java
/** * Called when message is received./*from w w w .j a v a2 s . c o m*/ * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { Log.d(TAG, "From: " + data); String message = data.getString("message"); ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses(); if (message != null) { if (message.startsWith("Ride has been cancelled by the driver")) { MyApplication.declinedriver = true; MyApplication.driverdeclinebookingid = data.getString("bookingId"); MyApplication.notificationconfiride = false; for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(getApplicationContext().getPackageName())) { Intent broadcastIntent = new Intent(); broadcastIntent.setAction("Driverdecline"); sendBroadcast(broadcastIntent); } else { } } } else { sendNotification(message); } } } if (message.startsWith("Dear")) { MyApplication.notimsg = data.getString("message"); MyApplication.notibookingId = data.getString("bookingId"); MyApplication.notipUser = data.getString("pUser"); MyApplication.notisUser = data.getString("sUser"); splitnotifiaction_flag = true; MyApplication.splitride = true; for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(getApplicationContext().getPackageName())) { Intent broadcastIntent = new Intent(); broadcastIntent.setAction("splitrideaccept"); sendBroadcast(broadcastIntent); } else { } } } else { sendNotification(message); } } /* Intent i = new Intent("AcceptNotificationUIwork"); sendBroadcast(i);*/ } if (message.equals("ride complete successfully")) { MyApplication.radeyourrite = true; MyApplication.notificationconfiride = false; MyApplication.RateyourRide = false; flag = true; MyApplication.rideDriverComplete = new RideDriverComplete(); String driverName = data.getString("driverName"); String pickLat = data.getString("pickLat"); String pickLong = data.getString("pickLong"); String destLat = data.getString("destLat"); String destLong = data.getString("destLong"); String pickupaddress = data.getString("pickupaddress"); String destinationaddress = data.getString("destinationaddress"); String driverId = data.getString("driverId"); String vehicle = data.getString("vehicle"); String totalfare = data.getString("total_fare"); String rideId = data.getString("rideId"); MyApplication.RideId = rideId; String licenseId = data.getString("licenseId"); if (message != null) { MyApplication.rideDriverComplete.setMessageride(message); } else { MyApplication.rideDriverComplete.setMessageride(""); } if (driverName != null) { MyApplication.rideDriverComplete.setDriverNameride(driverName); } else { MyApplication.rideDriverComplete.setDriverNameride(""); } if (pickLat != null) { MyApplication.rideDriverComplete.setPickLatride(pickLat); } else { MyApplication.rideDriverComplete.setPickLatride(""); } if (pickLong != null) { MyApplication.rideDriverComplete.setPickLongride(pickLong); } else { MyApplication.rideDriverComplete.setPickLongride(""); } if (destLat != null) { MyApplication.rideDriverComplete.setDestLatride(destLat); } else { MyApplication.rideDriverComplete.setDestLatride(""); } if (destLong != null) { MyApplication.rideDriverComplete.setDestLongride(destLong); } else { MyApplication.rideDriverComplete.setDestLongride(""); } if (driverId != null) { MyApplication.rideDriverComplete.setDriverIdride(driverId); } else { MyApplication.rideDriverComplete.setDriverIdride(""); } if (vehicle != null) { MyApplication.rideDriverComplete.setVehicle(vehicle); } else { MyApplication.rideDriverComplete.setVehicle(""); } if (rideId != null) { MyApplication.rideDriverComplete.setRideId(rideId); } else { MyApplication.rideDriverComplete.setRideId(""); } if (licenseId != null) { MyApplication.rideDriverComplete.setLicenseId(licenseId); } else { MyApplication.rideDriverComplete.setLicenseId(""); } if (totalfare != null) { MyApplication.rideDriverComplete.setTotalfare(totalfare); } else { MyApplication.rideDriverComplete.setTotalfare(""); } if (pickupaddress != null) { MyApplication.rideDriverComplete.setPickupaddress(pickupaddress); } else { MyApplication.rideDriverComplete.setPickupaddress(""); } if (destinationaddress != null) { MyApplication.rideDriverComplete.setDestinationaddress(destinationaddress); } else { MyApplication.rideDriverComplete.setDestinationaddress(""); } for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(getApplicationContext().getPackageName())) { MyApplication.pickuploction = false; Intent broadcastIntent = new Intent(); broadcastIntent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete); broadcastIntent.setAction("DriverNotificationcomplete"); sendBroadcast(broadcastIntent); } else { } } } } } } for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(getApplicationContext().getPackageName())) { } else { System.out.println("App in background state"); sendNotification(message); } } } else { System.out.println("App in background state"); sendNotification(message); } } }
From source file:nu.yona.app.api.service.ActivityMonitorService.java
private static String printForegroundTask(Context context) { currentApp = "NULL"; try {//w w w.j ava 2 s . c o m if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE); long time = System.currentTimeMillis(); List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - AppConstant.ONE_SECOND * AppConstant.ONE_SECOND, time); if (appList != null && appList.size() > 0) { SortedMap<Long, UsageStats> mySortedMap = new TreeMap<>(); for (UsageStats usageStats : appList) { mySortedMap.put(usageStats.getLastTimeUsed(), usageStats); } if (!mySortedMap.isEmpty()) { currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName(); } } } else { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); currentApp = am.getRunningAppProcesses().get(0).processName; } } catch (Exception e) { AppUtils.reportException(ActivityMonitorService.class.getSimpleName(), e, Thread.currentThread()); } return currentApp; }
From source file:com.yamin.kk.vlc.BitmapCache.java
private BitmapCache() { // Get the global context of the application Context context = VLCApplication.getAppContext(); // Get memory class of this device, exceeding this amount will throw an // OutOfMemory exception. final int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass();// ww w. ja v a 2 s .co m // Use 1/5th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 5; Log.d(TAG, "LRUCache size sets to " + cacheSize); mMemCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:org.couchtatertot.helper.PosterCache.java
private PosterCache(Context c) { this.cacheDir = new File(c.getExternalCacheDir(), cacheFolder); this.cacheDir.mkdirs(); int memClass = ((ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); // use half of the memory unless we have less then 32MB int cacheSize = memClass * 1024 * 1024 / 2; if (memClass < 32) cacheSize = memClass * 1024 * 1024 / 4; this.memCache = new LruCache<String, Bitmap>(cacheSize) { @Override//from ww w . j a va 2s . c o m protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:org.videolan.libvlc.BitmapCache.java
private BitmapCache() { // Get the global context of the application Context context = KsApplication.getAppContext(); // Get memory class of this device, exceeding this amount will throw an // OutOfMemory exception. final int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass();// w ww . jav a2s.com // Use 1/5th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 5; Log.d(TAG, "LRUCache size sets to " + cacheSize); mMemCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap value) { return value.getRowBytes() * value.getHeight(); } }; }
From source file:cn.apputest.ctria.service.UploadFailRecordService.java
public static boolean isServiceRunning(Context context, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningServiceInfo> serviceInfos = activityManager .getRunningServices(Constants.RETRIVE_SERVICE_COUNT); if (null == serviceInfos || serviceInfos.size() < 1) { return false; }//w w w.j av a 2 s .com for (int i = 0; i < serviceInfos.size(); i++) { if (serviceInfos.get(i).service.getClassName().contains(className)) { isRunning = true; break; } } Log.i("ServiceUtil-AlarmManager", className + " isRunning = " + isRunning); return isRunning; }