how can I get the name of the actual app program that is currently running?
Environment: sdk version 23J Android studio3.1 oppoA59s
2.Service Code
//Activity
final ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
new Thread(){
public void run() {
while(true){
try {
List< ActivityManager.RunningTaskInfo > runningTaskInfo = am.getRunningTasks(1);
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
Log.i(TAG, componentInfo.getPackageName());
sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
}
};
}.start();
manifest.xml Code
<uses-permission android:name="android.permission.GET_TASKS"></uses-permission>
but the current app name I got when I opened another app seems to be hidden by the android system. All display com.oppo.launcher.