확인
<service android:name=".Services.MyCustomNotificationListener"
android:label="MyAppName"
android:exported="true"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
이것이 잘 시험되지 않는다. 나는 단지 같은 문제를 가진 다른 사람들을 돕기 위해 그것을 버리고 싶었다. OREO 장치가 알림을 받도록하려면 onListenerConnected 및 getActiveNotification()을 사용해야합니다.
public class ListenForNotificationsService extends NotificationListenerService {
private String TAG = this.getClass().getSimpleName();
@Override
@TargetApi(Build.VERSION_CODES.N)
public void onListenerConnected() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
getActiveNotifications();
}
Log.d(TAG, "Listener connected");
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.d(TAG, "Notification received");
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
if (sbn.getPackageName() != null) {
Log.d(TAG, "Notification removed:" + sbn.getPackageName() + ":" + sbn.getId());
}
}
@Override
@TargetApi(Build.VERSION_CODES.N)
public void onListenerDisconnected() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// Notification listener disconnected - requesting rebind
requestRebind(new ComponentName(this, NotificationListenerService.class));
}
}
}
onListenerDisconnected은() 때문에 사용에주의해야 올바른 또는 경우 나도 몰라, 참고 : 여기 내 코드입니다. 또 다른 생각은 OREO의 깊은 수면 변경으로 인해이를 처리하는 데 필요한 다른 것이있을 수 있다는 것입니다. YMMV, 많은 시간을 낭비 했으므로 다른 사람을 도울 수 있기를 바랍니다.
oreo가 알림 채널과 관련하여 새로운 변경 사항을 보았습니다. https://developer.android.com/reference/android/service/notification/NotificationListenerService.html –
답장을 보내 주셔서 감사합니다. @vikas. 대답 좀 더 자세히 설명해 주시겠습니까? –
올해 Google IO에는 Oreo를 타겟팅하는 경우 채널을 통해서만 알림을 추가해야한다는 내용의 공지가있었습니다. 그렇지 않은 경우에는 더 많이 볼 수있는 경우 삭제됩니다. –