// 判断是否开启监听通知权限
if (NotificationManagerCompat.getEnabledListenerPackages(this).contains(getPackageName())) {
Intent serviceIntent =new Intent(this, GuardNotificationListenerService.class);
startService(serviceIntent);
}else {
// 去开启 监听通知权限
startActivity(new Intent(“android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS”));
}
}
实现监听服务 NotificationListenerService
import android.app.Notification;
import android.nfc.Tag;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.text.SpannableString;
import android.text.TextUtils;
import com.mo.util.Log;
/**
-
@Description:
-
@Author: lhw
-
@CreateDate: 2020/2/22 17:59
*/
public class Guar