【问题标题】:Send message to LogCat向 LogCat 发送消息
【发布时间】:2014-07-23 18:20:57
【问题描述】:

我正在寻找一种向自己发送消息以在设备上调试我的应用程序的方法。如果我理解正确LogCat 用于此。但我无法向LogCat 发送/输出消息。

我尝试了以下没有结果:

System.out.println("Message"); //Outputs to console when in desktop app, nothing on device.
Log.i + Log.d + Log.w //These methods do not exist. And i cannot get `Log` to work in any other way.
Debug.println("Msg1", "Msg2"); //Ends up in a error on device.

我只是想在我的手机上给自己发送“调试”消息,比如点击坐标。如果此目的不需要LogCat,我不一定需要它。

【问题讨论】:

  • Log.d(String tag, String message) 方法有什么问题?
  • 他正在使用 LibGDX,它不允许您直接访问该 API。我在我的回答中指出了他应该使用哪些方法。
  • 我是这里唯一一个从 system.out.println 登录 android 的人?

标签: android eclipse debugging libgdx logcat


【解决方案1】:

android.util.Log 是具有您想要的方法的类,即 Log.i()、Log.w() 等。

如果它们“不存在”,请确保您正在导入该类。

编辑:抱歉,错过了 libgdx 标签。在 LibGDX 中,请改用以下方法:

Gdx.app.log("MyTag", "my informative message");
Gdx.app.error("MyTag", "my error message", exception);
Gdx.app.debug("MyTag", "my debug message");

【讨论】:

  • 谢谢,我其实也用过Gdx.app.log,但是没有看info级别。您可能还想添加它以供将来参考。
【解决方案2】:

如果您在核心 libgdx 项目中,请使用 Gdx.app.log("tag", "msg");。这会在 Android 构建中传递给 Android 的 Log.i()。您不能直接在核心项目中访问 Android API。

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2015-07-13
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 2019-11-13
    • 2017-12-27
    相关资源
    最近更新 更多