반응형
Android Custom NotificationView(RemoteViews)에 대해 알아 보자
Android custom NotificationView를 찾다가 RemoteViews라는게 있었습니다!
notification 을 원하는 형태로 그릴 수 있었습니다!
val acceptIntent = Intent(this, 원하는화면::class.java)
val rejectIntent = Intent(this, 원하는화면::class.java)
RemoteViews(packageName, R.layout.보여줄xml).let {
val contents = "원하는 내용"
it.setTextViewText(R.id.textview1, "내용")
it.setTextViewText(R.id.textview2, "내용")
it.setOnClickPendingIntent(
R.id.accept_button,
PendingIntent.getBroadcast(
this,
0,
acceptIntent,
PendingIntentKt.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT
)
)
it.setOnClickPendingIntent(
R.id.reject_button,
PendingIntent.getBroadcast(
this,
0,
rejectIntent,
PendingIntentKt.FLAG_IMMUTABLE or PendingIntent.FLAG_CANCEL_CURRENT
)
)
val notiIntent =
Intent(this, ConnectingActivity::class.java).addFlags(FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val builder = NotificationCompat.Builder(this, 채널ID)
builder
.setCustomContentView(it)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setShowWhen(false)
.setOngoing(true)
.setContentText(contents)
.setSmallIcon(R.drawable.ic_notification_red)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setFullScreenIntent(
PendingIntent.getActivity(
this,
0,
notiIntent,
PendingIntentKt.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
), true
)
.setCategory(Notification.CATEGORY_CALL)
.build()
.run { startForeground(KINOLINK_NOTIFICATION_ID, this) }
var image = "image url"
//노티 내부에 Glide 를 적용할 Target View
val notificationTarget = NotificationTarget(
this,
R.id.target_user_image_view,
it,
builder.build(),
노티피케이션ID
)
//위에서 가져온 View 에 Glide 를 적용해서 원형태로 만든다
Glide
.with(this)
.asBitmap()
.load(imageSmall)
.into(notificationTarget)
}
xml
ConstraintLayout은 지원하지 않았던 걸로 기억합니다!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="32dp"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp">
<ImageView
android:id="@+id/notification_icon_image_view"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:src="@drawable/ic_notification_red"
tools:ignore="contentDescription" />
<TextView
android:id="@+id/tvNotificationContents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/notification_icon_image_view"
android:ellipsize="end"
android:lineSpacingExtra="0dp"
android:singleLine="true"
android:text="@string/connecting_notification_calling_contents"
android:textColor="@color/notification_main_color"
android:textSize="12dp"
tools:ignore="SpUsage" />
</RelativeLayout>
참조 : https://stackoverflow.com/questions/21925688/adding-button-action-in-custom-notification
반응형
'안드로이드' 카테고리의 다른 글
[Android] 스토어 배포 경고 (디버그 기호 업로드) (0) | 2024.05.20 |
---|---|
[Android] RecyclerView GridLayoutManager 헤더, 푸터, spanSizeLookup 작업 (0) | 2024.05.10 |
[Android] 안드로이드 잠금 화면, 슬립 깨우기 (0) | 2024.03.26 |
아키텍처는 왜 중요한가? (MVC, MVP, MVVM, Clean Architecture, ViewModel, 모듈) 알아 보자! (0) | 2024.03.26 |
[Android] 루팅이란? 루팅 체크 방법 (0) | 2024.03.22 |