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.adjust.sdk.ActivityHandler.java
public static ActivityHandler getInstance(AdjustConfig adjustConfig) { if (adjustConfig == null) { AdjustFactory.getLogger().error("AdjustConfig missing"); return null; }/* ww w. j a v a 2s .c o m*/ if (!adjustConfig.isValid()) { AdjustFactory.getLogger().error("AdjustConfig not initialized correctly"); return null; } if (adjustConfig.processName != null) { int currentPid = android.os.Process.myPid(); ActivityManager manager = (ActivityManager) adjustConfig.context .getSystemService(Context.ACTIVITY_SERVICE); if (manager == null) { return null; } for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) { if (processInfo.pid == currentPid) { if (!processInfo.processName.equalsIgnoreCase(adjustConfig.processName)) { AdjustFactory.getLogger().info("Skipping initialization in background process (%s)", processInfo.processName); return null; } break; } } } ActivityHandler activityHandler = new ActivityHandler(adjustConfig); return activityHandler; }
From source file:com.tencent.mars.sample.SampleApplicaton.java
public static void openXlog() { if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (BuildConfig.DEBUG) { Xlog.setConsoleLogOpen(true); } else {/*from w ww .ja va 2s . c om*/ Xlog.setConsoleLogOpen(false); } Log.setLogImp(new Xlog()); } else { int pid = android.os.Process.myPid(); String processName = null; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningAppProcessInfo appProcess : am.getRunningAppProcesses()) { if (appProcess.pid == pid) { processName = appProcess.processName; break; } } final String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath(); final String logPath = SDCARD + "/marssample/log"; String logFileName = processName.indexOf(":") == -1 ? "MarsSample" : ("MarsSample_" + processName.substring(processName.indexOf(":") + 1)); if (BuildConfig.DEBUG) { Xlog.appenderOpen(Xlog.LEVEL_VERBOSE, Xlog.AppednerModeAsync, "", logPath, logFileName); Xlog.setConsoleLogOpen(true); } else { Xlog.appenderOpen(Xlog.LEVEL_INFO, Xlog.AppednerModeAsync, "", logPath, logFileName); Xlog.setConsoleLogOpen(false); } Log.setLogImp(new Xlog()); } }
From source file:com.teegarcs.mocker.internals.MockerInternals.java
public static boolean isAppOnForeground(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = am.getRunningTasks(1); return taskInfo.get(0).topActivity.getPackageName().equals(context.getApplicationInfo().packageName); }
From source file:com.mobivery.greent.MVYBatteryManagerActivityFragment.java
public static boolean isApplicationBroughtToBackground(final Activity activity) { ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1); // Check the top Activity against the list of Activities contained in the Application's package. if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; try {/*from www .j a v a 2 s . co m*/ PackageInfo pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES); for (ActivityInfo activityInfo : pi.activities) { if (topActivity.getClassName().equals(activityInfo.name)) return false; } } catch (PackageManager.NameNotFoundException e) { return false; // Never happens. } } return true; }
From source file:Main.java
/** * Return <tt>true</tt> if the caller runs in a process dedicated to the Engagement service.<br/> * Return <tt>false</tt> otherwise, e.g. if it's the application process (even if the Engagement * service is running in it) or another process.<br/> * This method is useful when the <b>android:process</b> attribute has been set on the Engagement * service, if this method return <tt>true</tt>, application initialization must not be done in * that process. This method is used by {@link EngagementApplication}. * @param context the application context. * @return <tt>true</tt> if the caller is running in a process dedicated to the Engagement * service, <tt>false</tt> otherwise. * @see EngagementApplication//from w w w . j a v a 2 s .co m */ public static boolean isInDedicatedEngagementProcess(Context context) { /* Get our package info */ PackageInfo packageInfo; try { packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SERVICES); } catch (Exception e) { /* * NameNotFoundException (uninstalling?) or in some rare scenario an undocumented * "RuntimeException: Package manager has died.", probably caused by a system app process * crash. */ return false; } /* Get main process name */ String mainProcess = packageInfo.applicationInfo.processName; /* Get embedded Engagement process name */ String engagementProcess = null; if (packageInfo.services != null) for (ServiceInfo serviceInfo : packageInfo.services) if (SERVICE_CLASS.equals(serviceInfo.name)) { engagementProcess = serviceInfo.processName; break; } /* If the embedded Engagement service runs on its own process */ if (engagementProcess != null && !engagementProcess.equals(mainProcess)) { /* The result is to check if the current process is the engagement process */ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (RunningAppProcessInfo rapInfo : activityManager.getRunningAppProcesses()) if (rapInfo.pid == Process.myPid()) return rapInfo.processName.equals(engagementProcess); } /* Otherwise engagement is not running in a separate process (or not running at all) */ return false; }
From source file:com.nike.plusgps.nikeplusgallery.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dbHelper = new DBHelper(this); // Creates the database dbHelper.deleteAllResponse(); // Clears the JSON response cache dbHelper.deleteAllMedia(); // Clears the JSON images cache // Get memory class of this device, exceeding this amount will throw an // OutOfMemory exception. final int memClass = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); // Use 1/8th of the available memory for this memory cache. final int cacheSize = 1024 * 1024 * memClass / 8; mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @Override/*from ww w. jav a 2 s.c o m*/ protected int sizeOf(String key, Bitmap bitmap) { // The cache size will be measured in bytes rather than number of items. return bitmap.getByteCount(); } }; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { setContentView(R.layout.activity_main_port); GridView view = (GridView) findViewById(R.id.gridView); flickrFeedList = new ArrayList<FlickrFeed>(); new JSONParser() .execute("http://api.flickr.com/services/feeds/photos_public.gne?tags=nike&format=json"); adapter = new FlickrFeedAdapter(getApplicationContext(), R.layout.single_elem_port, flickrFeedList, dbHelper, mMemoryCache); view.setAdapter(adapter); } else { setContentView(R.layout.activity_main_land); carouselElement = (LinearLayout) findViewById(R.id.carousel); // Compute width of a carousel item based on screen width and initial item count final DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT); ImageView imageItem; String imgURL; for (int i = 0; i < flickrFeedList.size(); ++i) { imageItem = new ImageView(this); imgURL = flickrFeedList.get(i).getMedia(); new DownloadImageTask(imageItem).execute(imgURL); imageItem.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageWidth)); carouselElement.addView(imageItem); } } }
From source file:cc.psdev.heywifi.MainService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i("onStartCommand", "called"); wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); dm = new DBManager(getApplicationContext(), "data", null, DATABASE_VERSION); audm = (AudioManager) getSystemService(Context.AUDIO_SERVICE); actm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); pref = new SharedPrefSettings(this); Thread thread = new Thread(this); thread.start();//from w w w .jav a2 s .c o m return START_STICKY; }
From source file:com.google.android.apps.muzei.render.MuzeiRendererFragment.java
@Override @TargetApi(Build.VERSION_CODES.KITKAT)//from w w w . ja v a 2 s . co m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { boolean simpleDemoMode = false; if (mDemoMode && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { ActivityManager activityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); if (activityManager.isLowRamDevice()) { simpleDemoMode = true; } } if (simpleDemoMode) { DisplayMetrics dm = getResources().getDisplayMetrics(); int targetWidth = dm.widthPixels; int targetHeight = dm.heightPixels; if (!mDemoFocus) { targetHeight = MathUtil.roundMult4( ImageBlurrer.MAX_SUPPORTED_BLUR_PIXELS * 10000 / MuzeiBlurRenderer.DEFAULT_BLUR); targetWidth = MathUtil.roundMult4((int) (dm.widthPixels * 1f / dm.heightPixels * targetHeight)); } mSimpleDemoModeImageView = new ImageView(container.getContext()); mSimpleDemoModeImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); Picasso.with(getActivity()).load("file:///android_asset/starrynight.jpg") .resize(targetWidth, targetHeight).centerCrop().into(mSimpleDemoModeLoadedTarget); return mSimpleDemoModeImageView; } else { mView = new MuzeiView(getActivity()); mView.setPreserveEGLContextOnPause(true); return mView; } }
From source file:rus.cpuinfo.AndroidDepedentModel.DevInfo.java
@NonNull private ActivityManager.MemoryInfo getMemoryInfo() { ActivityManager activityManager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE); ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(mi);//from w w w . j a v a2s . c o m return mi; }
From source file:com.error.hunter.ListenService.java
@Override public void onCreate() { final Context context = getApplicationContext(); mActivityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); new Thread(new Runnable() { public void run() { while (true) { try { Thread.sleep(750); List<ActivityManager.ProcessErrorStateInfo> errList; errList = mActivityManager.getProcessesInErrorState(); if (errList != null) { Iterator<ActivityManager.ProcessErrorStateInfo> iter = errList.iterator(); while (iter.hasNext()) { ActivityManager.ProcessErrorStateInfo entry = iter.next(); for (String packageName : set) { if (entry.processName.equals(packageName)) { generateBugReport(entry); createNotification(context); strBuf.delete(0, strBuf.length()); errList.clear(); Thread.sleep(20000); }/*from w w w .j a va 2s .co m*/ } } } } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); }