首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在收听台式闹钟警报意图时,Logcat在广播接收器的onReceive内不工作

在收听台式闹钟警报意图时,Logcat在广播接收器的onReceive内不工作
EN

Stack Overflow用户
提问于 2016-04-22 01:49:08
回答 3查看 1.7K关注 0票数 3

我正在用我的广播接收器收听台式闹钟的更改意图。当我的广播接收器中的onReceive()方法被调用时,onReceive中的日志(Log.i/v())不会在安卓监视器上打印出来,但是Toast工作得很好。

清单文件:

代码语言:javascript
复制
<?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>

广播接收器:

代码语言:javascript
复制
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();
    }
} 
EN

回答 3

Stack Overflow用户

发布于 2017-06-17 08:18:20

也许为时已晚,但我把这个问题留给了未来的程序员,我也遇到了类似的问题,并用这种方法解决了它。

只需在Logcat面板中,将过滤列表框更改为"No Filters"

票数 4
EN

Stack Overflow用户

发布于 2016-04-22 03:28:03

您可能需要确保在DDMS透视图中选择了正确的设备,还需要确保选择了正确的筛选选项和日志级别-在您的情况下,您希望选择"verbose"。另外,还可以查看所选的答案和建议,了解为什么使用Logcat is not displaying logs

票数 0
EN

Stack Overflow用户

发布于 2020-08-26 20:20:04

您可以在BroadcastReceiver过滤器配置部分过滤日志以显示LogCat日志:

完整的解决方案步骤:Logs/logcat not working in BroadcastReceiver

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36776976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档