title: How do i get all current running process id in Android 8 and above
body: <pre><code>if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O){
              UsageStatsManager usm = (UsageStatsManager) context.getApplicationContext().getSystemService(&quot;usagestats&quot;);
              long time = System.currentTimeMillis();
              List&lt;UsageStats&gt; appListO = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 1000, time);
              if (appListO != null &amp;&amp; appListO.size() &gt; 0) {
                  for (UsageStats usageStats : appListO) {
                      Integer PID1= ? 
                   
                      unSortedMap.put(usageStats.getPackageName(), getUsage(PID1));
  
                  }
              }
  </code></pre>