- /**get the launcher status */
- private boolean isLauncherRunnig(Context context) {
- boolean result = false ;
- List<String> names = getAllTheLauncher();
- ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE) ;
- List<ActivityManager.RunningAppProcessInfo> appList = mActivityManager.getRunningAppProcesses() ;
- for (RunningAppProcessInfo running : appList) {
- if (running.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
- for (int i = 0; i < names.size(); i++) {
- if (names.get(i).equals(running.processName)) {
- result = true ;
- break;
- }
- }
- }
- }
- return result ;
- }
- private List<String> getAllTheLauncher(){
- List<String> names = null;
- PackageManager pkgMgt = this.getPackageManager();
- Intent it = new Intent(Intent.ACTION_MAIN);
- it.addCategory(Intent.CATEGORY_HOME);
- List<ResolveInfo> ra =pkgMgt.queryIntentActivities(it,0);
- if(ra.size() != 0){
- names = new ArrayList<String>();
- }
- for(int i=0;i< ra.size();i++)
- {
- String packageName = ra.get(i).activityInfo.packageName;
- names.add(packageName);
- }
- return names;
- }
- android 取当前显示的activity是什么
-
- ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
- ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
- Log.d("", "pkg:"+cn.getPackageName());
- Log.d("", "cls:"+cn.getClassName());
- private boolean isTopActivity(){
- List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
- if(tasksInfo.size() > 0){
- //应用程序位于堆栈的顶层
- if(packageName.equals(tasksInfo.get(0).topActivity.getPackageName())){
- return true;
- }
- }
- return false;
- }
- ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);