当前位置: 代码迷 >> Android >> android 怎么监听到 启动应用程序
  详细解决方案

android 怎么监听到 启动应用程序

热度:65   发布时间:2016-05-01 22:06:32.0
android 如何监听到 启动应用程序
比如 我点击 QQ这个应用程序,我想监听到用户点击了这个程序,或者说监听到用户启动了一个未知的程序。请指教!

------解决方案--------------------
Java code
/**     * 用来判断服务是否运行.     * @param context     * @param className 判断的服务名字:包名+类名     * @return true 在运行, false 不在运行     */          public boolean isServiceRunning(Context context,String className) {                      boolean isRunning = false;              ActivityManager activityManager =                   (ActivityManager)context.getSystemService(ACTIVITY_SERVICE);               List<ActivityManager.RunningServiceInfo> serviceList               = activityManager.getRunningServices(Integer.MAX_VALUE);              if (!(serviceList.size()>0)) {                  return false;              }              for (int i=0; i<serviceList.size(); i++) {                  if (serviceList.get(i).service.getClassName().equals(className) == true) {                      isRunning = true;                      break;                  }              }              Log.i(TAG,"service is running?=="+isRunning);              return isRunning;          }
  相关解决方案