List of usage examples for android.app ActivityManager getRunningTasks
@Deprecated public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException
From source file:system.info.reader.java
public String refresh() { //wifi// w ww .j av a 2s . c om WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if ((wifiInfo != null) && (wifiInfo.getMacAddress() != null)) Properties.setInfo((String) propertyItems[4], wifiInfo.getMacAddress()); else Properties.setInfo((String) propertyItems[4], "not avaiable"); //String tmpsdcard = runCmd("df", ""); //if (tmpsdcard != null) result += tmpsdcard + "\n\n"; //setMap("dpi", dpi); //location LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); List ll = lm.getProviders(true); Boolean foundLoc = false; for (int i = 0; i < ll.size(); i++) { Location lo = lm.getLastKnownLocation((String) ll.get(i)); if (lo != null) { Properties.setInfo((String) propertyItems[3], lo.getLatitude() + ":" + lo.getLongitude()); foundLoc = true; break; } } if (!foundLoc) Properties.setInfo((String) propertyItems[3], getString(R.string.locationHint)); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List serviceList = am.getRunningServices(10000); serviceInfo = ""; for (int i = 0; i < serviceList.size(); i++) { RunningServiceInfo rs = (RunningServiceInfo) serviceList.get(i); serviceInfo += rs.service.flattenToShortString() + "\n"; } //result += getString(R.string.nService) + serviceList.size() + "\n";//service number psInfo = ""; List appList = am.getRunningAppProcesses(); for (int i = 0; i < appList.size(); i++) { RunningAppProcessInfo as = (RunningAppProcessInfo) appList.get(i); psInfo += as.processName + "\n"; } //result += getString(R.string.nProcess) + appList.size() + "\n";//process number taskInfo = ""; List taskList = am.getRunningTasks(10000); for (int i = 0; i < taskList.size(); i++) { RunningTaskInfo ts = (RunningTaskInfo) taskList.get(i); taskInfo += ts.baseActivity.flattenToShortString() + "\n"; } //result += getString(R.string.nTask) + taskList.size() + "\n\n";//task number //result += getString(R.string.nProcess) + runCmd("ps", "") + "\n";//process number //setMap(getString(R.string.nApk), nApk); //send message to let view redraw. Message msg = mRedrawHandler.obtainMessage(); mRedrawHandler.sendMessage(msg); //properListItemAdapter.notifyDataSetChanged();//no use? Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(400); return ""; }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
public String getAppName() { String packagename;// w w w . j a va 2 s. c o m if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { KeyguardManager myKM = (KeyguardManager) getApplicationContext() .getSystemService(Context.KEYGUARD_SERVICE); if (myKM.inKeyguardRestrictedInputMode()) { //it is locked System.out.println("[AppLogger]Screen is locked"); packagename = "LockScreen"; } else { //it is not locked ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; packagename = componentInfo.getPackageName(); System.out.println( "[AppLogger]Build Version:" + Build.VERSION.SDK_INT + ",Package Name:" + packagename); } } else { KeyguardManager myKM = (KeyguardManager) getApplicationContext() .getSystemService(Context.KEYGUARD_SERVICE); if (myKM.inKeyguardRestrictedInputMode()) { //it is locked System.out.println("[AppLogger]Screen is locked"); packagename = "LockScreen"; } else { //ActivityManager am =(ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); //packagename = am.getRunningAppProcesses().get(0).processName; packagename = getTopPackage(); } System.out.println( "[AlarmReceiver]Build Version:" + Build.VERSION.SDK_INT + "Package Name:" + packagename); } return packagename; }
From source file:org.deviceconnect.android.deviceplugin.host.HostDeviceService.java
/** * ??????Activity????./*from w w w . j a v a 2s.com*/ * * @return ?? */ private String getClassnameOfTopActivity() { ActivityManager mActivityManager = (ActivityManager) getContext() .getSystemService(Service.ACTIVITY_SERVICE); String mClassName = mActivityManager.getRunningTasks(1).get(0).topActivity.getClassName(); return mClassName; }
From source file:net.kidlogger.kidlogger.KLService.java
private void doScanTask() { ActivityManager actMng = (ActivityManager) KLService.this.getSystemService(ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = actMng.getRunningTasks(1); String packageName = taskInfo.get(0).topActivity.getPackageName(); if (!packageName.equalsIgnoreCase(prevPack)) { PackageManager pm = getPackageManager(); String currTask;/*w w w. j av a 2 s. com*/ //prevPack = packageName; prevPack = new String(packageName); try { CharSequence cs = pm .getApplicationLabel(pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA)); currTask = cs.toString(); } catch (Exception e) { currTask = "unknown"; } if (!currTask.equals("unknown")) { final String ct = new String(currTask); new Thread(new Runnable() { public void run() { sync.writeLog(".htm", Templates.getApiLog(ct)); } }).start(); //WriteThread wt = new WriteThread(sync, ".htm", Templates.getApiLog(currTask)); } } }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * This method is called when the keyboard is shown * /*from w w w.j a v a2s . co m*/ * reset errors & suggestion picked counters * get dots and colourbar prefs * get injection prefs * update engine core prefs * prepare database for writing * create a new typing session * apply selected keyboard to input view * switch core engine dictionaries according to keyboard */ @Override public void onStartInputView(EditorInfo attribute, boolean restarting) { //Log.i("OnStartInputView","Keyboard about to be shown"); nInjections = 0; SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mInputView.dots = sharedPrefs.getBoolean("dots", false); mInputView.colorbar = sharedPrefs.getString("colorbar", "top"); mInputView.ycoords.clear(); mInputView.xcoords.clear(); mInputView.resetBackground(); errorInjection = sharedPrefs.getBoolean("errorinjection", false); errorInjectionThreshold = Integer.parseInt(sharedPrefs.getString("injectionThreshold", "20")); errorInjectionSound = sharedPrefs.getBoolean("errorinjectionsound", true); if (coreEngine != null) updateCorePrefs(); if (currentSession != null) { endSession(); } //open the database for writing if (dbm == null) dbm = new DBmanager(getApplicationContext()); dbm.open(); //get connection to editor field //ic = getCurrentInputConnection(); if (extractedText != null) { if (ic.deleteSurroundingText(9999, 0)) { ic.commitText(extractedText.text, 1); //extractedText=null; //Log.i("onStartInputView", "Text Replaced"); } else { //Log.i("onStartInputView", "IC not valid"); } } //create a new typing session UserPreferences up = new UserPreferences(); up.autocorrect = (sharedPrefs.getBoolean("autocorrect", true)) ? 1 : 0; up.sound = (sharedPrefs.getBoolean("audio", false)) ? 1 : 0; up.haptic = (sharedPrefs.getBoolean("vibrator", false)) ? 1 : 0; up.visual = (sharedPrefs.getBoolean("highlightwords", true)) ? 1 : 0; up.sugg_highlight = (sharedPrefs.getBoolean("suggestion_highlight", false)) ? 1 : 0; up.dots = (sharedPrefs.getBoolean("dots", false)) ? 1 : 0; currentSession = new TypingSession(up); currentSession.sess_height = mInputView.getHeight(); currentSession.sess_width = mInputView.getWidth(); currentSession.events.add(new TypingEvent(1, "Keyboard shown")); currentSession.user = userid; //find out what application has invoked the keyboard ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); if (android.os.Build.VERSION.SDK_INT < 21) //works only on Android <5, retrieve the app name { RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(1).get(0); String foregroundTaskPackageName = foregroundTaskInfo.topActivity.getPackageName(); PackageManager pm = this.getPackageManager(); PackageInfo foregroundAppPackageInfo; try { foregroundAppPackageInfo = pm.getPackageInfo(foregroundTaskPackageName, 0); currentSession.app = foregroundAppPackageInfo.applicationInfo.loadLabel(pm).toString(); //Log.i("OnStartInputView", "ForeGround app is "+foregroundAppPackageInfo.applicationInfo.loadLabel(pm).toString()); } catch (NameNotFoundException e) { e.printStackTrace(); } } else //retrieve the package name { List<RunningAppProcessInfo> ps = am.getRunningAppProcesses(); //Log.i("OnStartInput", "Running apps "+ps.size()); for (int x = 0; x < ps.size(); x++) { RunningAppProcessInfo p = ps.get(x); //Log.i("OnStartInput", "App is "+p.processName+p.importance); if (p.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { //Log.i("OnStartInput", "ForeGround app is "+p.processName); currentSession.app = p.processName; break; //the first one is the foreground app } } } // Apply the selected keyboard to the input view. //set the new keyboard options based on the temporary one created during OnStartInput if (mCurKeyboard != null) { //Log.i("onStartInputView","setting new keyboard to temp settings"); mInputView.setShifted(mCurKeyboard.isShifted()); mInputView.imeOptions = mCurKeyboard.imeOptions; } else { //Log.i("onStartInputView","mCurKeyboard is null"); } mInputView.currentKeyboard = startingKeyboard; mInputView.switchKeyboard(); if (coreEngine != null) { switch (mInputView.currentKeyboard) { case KeyboardViews.QWERTY_EL: coreEngine.activateLanguageKeymap(131092, null); coreEngine.setDictionaryPriority(131092, 0); break; case KeyboardViews.QWERTY_EN: coreEngine.activateLanguageKeymap(131081, null); coreEngine.setDictionaryPriority(131092, 1); break; } coreEngine.resetCoreString(); updateCandidates(); //KPTkeymapInfo(); } super.onStartInputView(attribute, restarting); }
From source file:com.android.mms.ui.MessageUtils.java
public static boolean isHome(Context context) { List<String> homePackageNames = getHomes(context); String packageName = ""; String className = ""; boolean ret = false; ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> rti = activityManager.getRunningTasks(2); if (rti != null && rti.size() > 0) { packageName = rti.get(0).topActivity.getPackageName(); className = rti.get(0).topActivity.getClassName(); }//from www. java2 s.c o m MmsLog.d(TAG, "package0= " + packageName + " class0=" + className); ret = homePackageNames.contains(packageName); if (!ret) { if ("com.mediatek.mms.ui.DialogModeActivity".equals(className)) { ret = true; } } /// M: fix bug ALPS00687923, check RunningAppProcessInfo IMPORTANCE_FOREGROUND @{ if (!ret) { List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); if (appProcesses == null || appProcesses.size() == 0) { MmsLog.d(TAG, "appProcesses == null || appProcesses.size() == 0"); ret = false; } else { for (RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals("com.android.launcher")) { MmsLog.d(TAG, "IMPORTANCE_FOREGROUND == com.android.launcher"); ret = true; } } } } /// @} return ret; }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
/** * Return true if the applications with the package name is running in foreground. * * @param pkgName application package name. *///from w w w . ja va 2 s. c o m private boolean isForegroundApp(String pkgName) { ActivityManager am = getContext().getSystemService(ActivityManager.class); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); return !tasks.isEmpty() && pkgName.equals(tasks.get(0).topActivity.getPackageName()); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
public String TopActivity() { String sRet = ""; ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = null; ComponentName componentInfo = null;//from w w w . jav a 2s .c o m if (aMgr != null) { taskInfo = aMgr.getRunningTasks(1); } if (taskInfo != null) { // topActivity: "The activity component at the top of the history stack of the task. // This is what the user is currently doing." componentInfo = taskInfo.get(0).topActivity; } if (componentInfo != null) { sRet = componentInfo.getPackageName(); } return (sRet); }
From source file:com.cognizant.trumobi.PersonaLauncher.java
public boolean isTopActivityIsPersonaLauncher() { boolean isTopActivityIsLauncher = false; ActivityManager mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); String className = mActivityManager.getRunningTasks(1).get(0).topActivity.getClassName(); System.out.println("top activity name " + className); if (className.equals("com.cognizant.trumobi.PersonaLauncher")) { isTopActivityIsLauncher = true;/*www. j a v a 2 s . c om*/ } return isTopActivityIsLauncher; }