title: Get Running Name App above Android 4
body: <p>I'm trying to get the Name of running apps, but it seems that it doesn't work for Android 5.</p>
  
  <p>This is the code that I'm using:</p>
  
  <pre><code>public class Check extends BroadcastReceiver {
  Tiempo tt=new Tiempo();
  public final String TAG = "CRAR"; // CheckRunningApplicationReceiver
  
  public void onReceive(Context aContext, Intent anIntent) {
  
  
  try {
  
  // Using ACTIVITY_SERVICE with getSystemService(String)
  // to retrieve a ActivityManager for interacting with the global system state.
  
  ActivityManager am = (ActivityManager) aContext
  .getSystemService(Context.ACTIVITY_SERVICE);
  
  // Return a list of the tasks that are currently running,
  // with the most recent being first and older ones after in order.
  // Taken 1 inside getRunningTasks method means want to take only
  // top activity from stack and forgot the olders.
  
  List&lt;ActivityManager.RunningTaskInfo&gt; alltasks = am
  .getRunningTasks(1);
  
  //
  for (ActivityManager.RunningTaskInfo aTask : alltasks) {
  
  // These are showing current running activity in logcat with
  // the use of different methods
  
  Log.i(TAG, "===============================");
  Log.i(TAG, "aTask.baseActivity: "
  + aTask.baseActivity.flattenToShortString());
  Log.i(TAG, "aTask.baseActivity: "
  + aTask.baseActivity.getClassName());
  Log.i(TAG, "aTask.topActivity: "
  + aTask.topActivity.flattenToShortString());
  Log.i(TAG, "aTask.topActivity: "
  + aTask.topActivity.getClassName());
  Log.i(TAG, "===============================");
  if(aTask.topActivity.getClassName().compareTo("com.jrdcom.launcher.Launcher")==0){
  tt.Detener();
  }else{
  tt.Contar();
  Log.e("tiempo encendido2", String.valueOf(tt.getSegundos()));
  }
  }
  
  } catch (Throwable t) {
  Log.i(TAG, "Throwable caught: "
  + t.getMessage(), t);
  }
  
  }
  }
  </code></pre>
  
  <p>When I run this code, the logcat shows this:</p>
  
  <pre><code>6240-6240/com.example.usuario.proy I/SR﹕ ===============================
  02-06 16:30:11.100    6240-6240/com.example.usuario.proy I/SR﹕ aTask.baseActivity: com.android.launcher/com.android.launcher2.Launcher
  02-06 16:30:11.100    6240-6240/com.example.usuario.proy I/SR﹕ aTask.baseActivity: com.android.launcher2.Launcher
  02-06 16:30:11.100    6240-6240/com.example.usuario.proy I/SR﹕ aTask.topActivity: com.android.launcher/com.android.launcher2.Launcher
  02-06 16:30:11.100    6240-6240/com.example.usuario.proy I/SR﹕ aTask.topActivity: com.android.launcher2.Launcher
  02-06 16:30:11.100    6240-6240/com.example.usuario.proy I/SR﹕ ===============================
  </code></pre>
  
  <p>Asyou can see, it show only the launcher, but there is no App name in Android 5. For Android 4 it works perfectly.</p>
  
  <p>Any idea?</p>
  
  <p>Thanks a lot.</p>