我正在用我的广播接收器收听台式闹钟的更改意图。当我的广播接收器中的onReceive()方法被调用时,onReceive中的日志(Log.i/v())不会在安卓监视器上打印出来,但是Toast工作得很好。
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dumbrella.ratemyday">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:process=":remote" android:name="AlarmClockReceiver">
<intent-filter>
<action android:name="com.android.deskclock.ALARM_DISMISS" />
<action android:name="com.android.deskclock.ALARM_SNOOZE" />
<action android:name="com.android.deskclock.ALARM_ALERT" />
<action android:name="com.android.deskclock.ALARM_DONE" />
</intent-filter>
</receiver>
</application>
</manifest>广播接收器:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import java.text.SimpleDateFormat;
public class AlarmClockReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// This log.v does not get printed on Android Monitor
Log.v("Broadcast Test", "In Broadcast Listener");
String message = "Broadcast intent detected "
+ intent.getAction();
// This toast gets displayed after the alarm is dismissed
Toast.makeText(context, message,Toast.LENGTH_LONG).show();
}
} 发布于 2017-06-17 08:18:20
也许为时已晚,但我把这个问题留给了未来的程序员,我也遇到了类似的问题,并用这种方法解决了它。
只需在Logcat面板中,将过滤列表框更改为"No Filters"。
发布于 2016-04-22 03:28:03
您可能需要确保在DDMS透视图中选择了正确的设备,还需要确保选择了正确的筛选选项和日志级别-在您的情况下,您希望选择"verbose"。另外,还可以查看所选的答案和建议,了解为什么使用Logcat is not displaying logs。
发布于 2020-08-26 20:20:04
您可以在BroadcastReceiver过滤器配置部分过滤日志以显示LogCat日志:

https://stackoverflow.com/questions/36776976
复制相似问题