Android Bubbles 알림 API 를 구현하려고하는데 작동하지 않고 일반 알림으로 표시됩니다. 에뮬레이터 API 30 (Android 11)에서 테스트 중입니다. 장치에서 작업 하는 사람 예제가 있고 대화 알림 지침을 따르고 있습니다.
- 알림은 MessagingStyle을 사용합니다.
- (앱이 Android 11 이상을 대상으로하는 경우에만 해당) 알림은 유효 수명이 긴 동적 또는 캐시 된 공유 바로 가기와 연결됩니다. 알림은 setShortcutId () 또는 setShortcutInfo ()를 호출하여이 연결을 설정할 수 있습니다. 앱이 Android 10 이하를 대상으로하는 경우 대체 옵션 섹션에 설명 된대로 알림을 바로 가기와 연결할 필요가 없습니다.
- 사용자가 게시 시점에 알림 채널 설정을 통해 대화 섹션에서 대화를 강등하지 않았습니다.
내가 무엇을 놓쳤는 지 말해주세요.
또한 Bubbles 디자인에 대한 몇 가지 선택적 질문이 있습니다.
이것이 내가 지금까지 얻은 것입니다
Recipient recipient = ...; // Sender data
Message message = ...; // Message data
Intent intent = new Intent(context, ChatActivity.class);
intent.putExtra(ChatActivity.CONVERSATION_ID, message.conversationId);
PendingIntent bubbleIntent =
PendingIntent.getActivity(context, 0, intent, 0);
IconCompat icon = loadIcon(recipient);
Person person = loadPerson(recipient, icon);
NotificationCompat.MessagingStyle style = getMessagingStyle(person);
createOrVerifyChannel();
Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setContentTitle(getNewMessagesCount(message) + " new messages with " + person.getName())
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentText(message.text)
.setBubbleMetadata(
new NotificationCompat.BubbleMetadata.Builder()
.setDesiredHeight(600)
.setIntent(bubbleIntent)
.setAutoExpandBubble(true)
.setSuppressNotification(true)
.setIcon(icon)
.build()
)
.addPerson(person)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setWhen(message.date)
.setStyle(style)
.setShortcutInfo(
new ShortcutInfoCompat.Builder(context, message.conversationId + "")
.setActivity(new ComponentName(context, ChatActivity.class))
.setCategories(new HashSet<>(Collections.singletonList(Notification.CATEGORY_MESSAGE)))
.setIcon(icon)
.setPerson(person)
.setRank(0)
.setShortLabel(person.getName())
.setIntent(intent)
.build()
)
.build();
NotificationManagerCompat.from(context).notify(message.id + "," + message.type,
message.id, notification);
명백한
<activity
android:name=".screens.chat.ChatActivity"
android:allowEmbedded="true"
android:resizeableActivity="true"
tools:targetApi="n" />
Gradle
targetSDKVersion 30
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
내가 놓친 것이 한 가지가 추가되었다 .setLongLived(true)
을 위해 ShortcutInfoCompat
. 문제를 해결합니다.
ShortcutInfo
한 번에 최대 5 개까지 가질 수 있기 때문에 앱 수준 에서 관리하는 것이 가장 좋다는 것을 배웠습니다 . 따라서 메모리에 캐싱하는 데 아무런 해가 없으며 Person
개체도 포함됩니다.
또한에 대한 LocusId 를 추가해야 합니다 NotificationCompat
.이 ID는 바로 가기, 알림 및보기간에 공유됩니다. 뷰에 추가하려면 ContentCaptureManager에 설명 된대로 추가 작업을해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다