Android – when listening to deskclock alarm intent, logcat cannot work in onReceive in the broadcast receiver

I am using my broadcast receiver to listen to the deskclock alert change intention. When the onreceive() method in my broadcast receiver is called, the log (log. I / v()) in onReceive will not be printed on the Android monitor, but toasts works normally

Manifest file:

<?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>

Broadcast receiver:

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();
    }
} 

resolvent:

Maybe it's too late, but I left it to the future programmer of this problem. I encountered a similar problem and solved it in this way. Just change the filter list box to "no filter" in the logcat panel

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>