gpt4 book ai didi

android - 使用自定义 View 创建自定义通知

转载 作者:行者123 更新时间:2023-11-29 15:42:24 24 4
gpt4 key购买 nike

我想创建一个像这样处理来电的通知

enter image description here

我尝试使用 RemoteViews 但没有成功。也许我无法与之互动。这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">

<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/title"
style="Custom Notification Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:text="aasdasdasd" />

<TextView
android:id="@+id/text"
style="Custom Notification Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_toRightOf="@id/image"
android:text="aasdasdasd" />

</LinearLayout>


<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

这是我的显示通知功能:

 private void customNotification() {
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.layout_custom_notification);


Intent intent = new Intent(this, CallingActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

remoteViews.setImageViewResource(R.id.image, R.drawable.bank);
remoteViews.setTextViewText(R.id.title, "Custom notification");
remoteViews.setImageViewResource(R.id.icon, R.drawable.individual);
remoteViews.setTextColor(R.id.title, ResourceUtil.getColorId(R.color.black));
remoteViews.setTextViewText(R.id.text, "This is a custom layout");
remoteViews.setTextColor(R.id.text, ResourceUtil.getColorId(R.color.black));
AppWidgetManager.getInstance(this).updateAppWidget(getComponentName(), remoteViews);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSound(defaultSoundUri)
.setOngoing(true)
.setContentTitle("Calling")
.setContentText("Message")
.setSmallIcon(R.drawable.login_logo)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setContent(remoteViews);


NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);


mNotificationManager.notify(1, builder.build());
}

有人能告诉我这件事吗?

最佳答案

这根本不需要自定义通知 - 这是使用标准 notification actions 的标准通知.

您看到的行为是 heads up notification ,仅当您使用 setFullScreenIntent() 时才会触发(这也是它长时间保持可见的方式)和/或具有高优先级并使用铃声或振动。

关于android - 使用自定义 View 创建自定义通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38364768/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com