我想获取在前台运行的应用程序的包名称。为此,我发现我们可以使用它:
ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> tasks = manager.getRunningAppProcesses();
Log.i("current_app", tasks.get(0).processName);
但当我检查the documentation时,它说:
Note: this method is only intended for debugging or building a user-facing process management UI.
为什么会这样?如果我们在生产中使用它(将被部署到公共游戏商店)有什么问题吗?