WEB开发网
开发学院手机开发Android 开发 列出 Android 设备中所有启动的服务 阅读

列出 Android 设备中所有启动的服务

 2010-09-10 01:04:00 来源:WEB开发网   
核心提示:for(int i = 0; i < mServiceList.size(); i ++){if(className.equals(mServiceList.get(i).service.getClassName())){return true;}}return false;}//获取所有启动的服务的类名priv

for(int i = 0; i < mServiceList.size(); i ++){

if(className.equals(mServiceList.get(i).service.getClassName())){

return true;

}

}

return false;

}

//获取所有启动的服务的类名

private String getServiceClassName(List mServiceList){

String res = "";

for(int i = 0; i < mServiceList.size(); i ++){

res+=mServiceList.get(i).service.getClassName()+ " ";

}

return res;

}

}

package com.tutor.runningservice;

import java.util.List;

import android.app.Activity;

import android.app.ActivityManager;

import android.os.Bundle;

import android.widget.TextView;

public class RunningService extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//setContentView(R.layout.main);

TextView mTextView = new TextView(this);

ActivityManager mActivityManager =

(ActivityManager)getSystemService(ACTIVITY_SERVICE);

List mServiceList = mActivityManager.getRunningServices(30);

//我要判断的服务名字,我在launcher2里加了一个音乐服务

final String musicClassName = "com.android.launcher2.MusicService";

boolean b = MusicServiceIsStart(mServiceList, musicClassName);

mTextView.setText("你要判断的服务状态为: " +b+" " + getServiceClassName(mServiceList));

setContentView(mTextView);

}

//通过Service的类名来判断是否启动某个服务

private boolean MusicServiceIsStart(List mServiceList,String

Tags:列出 Android 设备

编辑录入:coldstar [复制链接] [打 印]
赞助商链接