`

[AndroidTips]List of Running Applications

 
阅读更多

Get a list of running applications, and then check to see if a specific application is running.

 

package dreamincode.help;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.widget.Toast;
import android.widget.TextView;
import java.util.List;
import android.os.Bundle;

public class help_dic extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		TextView tv = new TextView(this);
		this.setContentView(tv);
		
		ActivityManager actvityManager = (ActivityManager)
		this.getSystemService( ACTIVITY_SERVICE );
		List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
		for(int i = 0; i < procInfos.size(); i++)
		{
				tv.setText(tv.getText().toString()+procInfos.get(i).processName+ 
							" " + String.valueOf(procInfos.get(i).processName.length())+"\n");
				if(procInfos.get(i).processName.equals("com.android.camera")) {
					Toast.makeText(getApplicationContext(), "Camera App is running", Toast.LENGTH_LONG).show();
				}
		}
	}
}

 

ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while(i.hasNext()) {
  ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
  try {
    CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
    Log.w("LABEL", c.toString());
  }catch(Exception e) {
    //Name Not FOund Exception
  }
}
 
分享到:
评论

相关推荐

    Android代码-Android-Tips

    This is an awesome list of tips for android. If you are a beginner, this list will be the first choice for you when you have a difficult time. Welcome Star and Fork, your support is my greatest ...

    List of Android UI/UX Libraries.zip

    List of Android UI/UX Libraries.zip,一份精选的android ui/ux库列表

    Android代码-Android-Applications-Info

    Simple android application that shows all information available about all installed apps. It can be a good source of inspiration for all beginners. It deals with activities, multi pane, fragments, ...

    Android 保存List数据(SharedPreferences)

    Android系统提供了`org.json`库,我们可以使用`JSONArray`和`JSONObject`来序列化和反序列化List。例如: ```java List&lt;String&gt; dataList = new ArrayList(); // 添加数据到dataList // 序列化 JSONArray ...

    Android list转json工具类

    当需要将Android应用中的数据列表发送到服务器或者从服务器获取数据时,通常需要将List对象转换为JSON字符串。本篇文章将深入探讨如何在Android中实现一个将集合List转化为JSON字符串的工具类,以及在联网调接口时...

    Android Layer List使用实例

    Layer List是Anroid中的一种图形的方式,它是通过叠加若干张图片的方式来形成最终的图片,最终的图片在代码中表现为一个LayerDrawable对象。在android UI 开发中会经常遇到。因此我们有发现好好学习了解它的使用方法...

    Getting rid of Window List from MDI applications在MDI应用中

    标题中的“Getting rid of Window List from MDI applications”指的是在多文档界面(Multiple Document Interface, MDI)应用程序中移除窗口列表的操作。在Windows操作系统中,MDI是一种允许在一个父窗口内同时显示...

    Android里List时间升序排序

    在Android开发中,数据的排序是一项常见的操作,特别是在处理列表数据时。本篇文章将深入探讨如何在`List&lt;String&gt;`中实现日期的升序排序。在实际应用中,我们经常遇到日期字符串格式不一致的情况,这使得直接使用`...

    The lists of TASK_RUNNING processes

    The lists of TASK_RUNNING processes http://blog.csdn.net/songqqnew/article/details/6759649

    Android自定义list的item显示内容

    本篇文章将深入探讨如何在Android中实现自定义list的item显示内容。 首先,我们需要创建一个自定义的布局文件,这个布局文件将作为ListView中的每个item。在`res/layout`目录下创建一个新的XML布局文件,例如`...

    AIDL List传递 String传递(android studio)

    在这个"AIDL List传递 String传递(android studio)"的示例中,我们将深入探讨如何通过AIDL处理List数据和String数据的传递。 首先,让我们理解AIDL的基本结构。AIDL文件是一个文本文件,它定义了一个接口,这个...

    Curated_list_of_awesome_GAN_applications_a

    Curated_list_of_awesome_GAN_applications_and_demo_gans-awesome-applications

    List index out of bounds(-1)错误解决办法

    解决办件运行弹出List index out of bounds错误.

    android的list开发实例代码

    本教程将深入讲解如何在Android中实现一个包含图片的List开发实例。 首先,我们需要创建一个基本的ListView布局。在`res/layout`目录下创建一个新的XML文件,例如`list_item.xml`,来定义每个列表项的视图。这个...

    android中list数据与json互转

    本篇主要介绍如何在Android中进行`List`数据与JSON的相互转换。 一、JSON简介 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成。它的结构基于两种基本...

    Learning Kotlin by building Android Applications

    The book begins by giving you a strong grasp of the Kotlin language and its APIs as a preliminary to building stunning applications for Android. You'll learn to set up an environment as the difficulty...

    Android 获取手机所有已安装的应用,并可以打开它

    List&lt;ApplicationInfo&gt; installedApps = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES); for (ApplicationInfo app : installedApps) { if (!(app.flags & ApplicationInfo.FLAG_SYSTEM...

    android 存取list到sharedprefence

    android 存取list到sharedprefence,里面两个函数,一个存入,一个读出

    缓存一个list的内容进txt文件,Android

    在Android开发中,缓存是一种常见的优化策略,用于提高数据加载速度和减少网络请求。当应用需要频繁访问相同数据时,将数据缓存到本地可以显著提升用户体验。本话题主要探讨如何将一个list的内容缓存到TXT文件中,并...

    复杂网络大家名著:Complex Networks---Principles, Methods and Applications书籍配套数据

    For each data set you find below a brief description and a list of salient properties (number of node, number of edges, etc.). All data sets All the data sets of the textbook are available for ...

Global site tag (gtag.js) - Google Analytics