要求是制作自定义通知,因为android的默认通知仅允许图像.因此,我详细介绍了如何在扩展时附加自定义UI以进行通知,准备好的答案是创建自定义视图并传递给通知管理器并允许从API级别16开始.所以我做了一个,这里是我的布局xml代码 - filename:notification_custom_view_new:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GhostWhite">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="65dp">
<ImageView
android:id="@+id/big_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:scaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/big_icon"
android:layout_alignTop="@+id/big_icon"
android:layout_toRightOf="@+id/big_icon"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.6"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Title"
android:textColor="@color/colorBlackDimText"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:paddingTop="2dp"
android:text="message"
android:textColor="@color/colorBlackDimText"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center">
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:padding="8dp"
android:text="24:59"
android:textColor="@color/colorBlackDimText"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:id="@+id/shadow" …Run Code Online (Sandbox Code Playgroud) 我刚刚注意到一些函数NotificationManager处理一个被调用的类AutomaticZenRule:
和别的...
看看AutomaticZenRule的文档,它仍然没有说明它是什么,它可以用于什么:
zen模式的规则实例信息.
在互联网上搜索,我只能在Commonsware博客文章中看到,他们想知道它是什么:
目前还不清楚AutomaticZenRule是什么......
我发现它几乎没有什么.不是"zen模式"而不是"AutomaticZenRule".
什么是"禅模式"?
什么是"AutomaticZenRule",我该怎么办呢?它与通知有什么关系?
Android N上有什么特别之处,这个版本上添加了这个API吗?
有使用它的样品吗?
Android:我正在尝试在安装软件包后取消通知栏中的通知.我正在做的是以下内容:
public class MyBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "MyBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
Uri data = intent.getData();
//some code goes here
//get the id of the notification to cancel in some way
notificationhelper._completeNotificationManager.cancel(id);
}
}
}
Run Code Online (Sandbox Code Playgroud)
哪里
public class notificationhelper {
public static NotificationManager _completeNotificationManager = null;
public void complete() {
if (_completeNotificationManager == null)
_completeNotificationManager = (NotificationManager) _context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification( …Run Code Online (Sandbox Code Playgroud) 我在我的应用上使用推送通知.我曾经在推送通知到来时显示通知,如果我发送另一个通知(不清除先前的通知),它会替换新通知.
这是我使用的代码
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "New notification Pending";
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, time);
notification.flags = Notification.DEFAULT_LIGHTS
| Notification.FLAG_AUTO_CANCEL;
// Context context = getApplicationContext();
CharSequence contentTitle = "Notifications";
CharSequence contentText = newMessage;
Intent notificationIntent = new Intent(this, LoginActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
mNotificationManager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud)
但我不想替换通知,我想将其添加为新通知.
有人知道通过id获取通知的方式吗?如果它仍然显示在Android的状态栏中,想要获取信息并将其添加到新通知中,则我想要获取新通知.谢谢.
package com.test.app;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class runOnBoot extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试构建软件包时,它说
compile:
[javac] Compiling 2 source files to /home/mrburns/Desktop/myapp/bin/classes
[javac] /home/mrburns/Desktop/myapp/src/com/test/app/runOnBoot.java:14: cannot find symbol
[javac] symbol : variable NOTIFICATION_SERVICE
[javac] location: class runOnBoot
[javac] NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
[javac] ^
[javac] 1 error
BUILD FAILED
Run Code Online (Sandbox Code Playgroud) 我试图Notify基于一些标准的用户.Multiple Notifications正在显示,Status Bar但我想Group the notification in single notification,当用户点击时Status Bar,我想检索该组中的所有通知.那可能吗?或者我必须保留PendingIntents这些通知?任何帮助将不胜感激.例如,如果两个朋友的生日在同一天出现,则应显示2个通知.我想结合这些通知,即在状态栏中不是2个通知,我想要一个,当用户点击它时,它应该有2个通知的信息.可能吗?
请参阅以下代码以显示通知.
public void displayNotification(BirthdayDetail detail)
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle(detail.getContactName());
builder.setContentText(detail.getContactBirthDate());
Intent resultIntent = new Intent(this.context, NotificationView.class);
resultIntent.putExtra("name", detail.getContactName());
resultIntent.putExtra("birthdate", detail.getContactBDate());
resultIntent.putExtra("picture_path", detail.getPicturePath());
resultIntent.putExtra("isContact", detail.isFromContact());
resultIntent.putExtra("notificationId", notificationId);
if(detail.isFromContact())
{
resultIntent.putExtra("phone_number", detail.getPhoneNumber());
}
PendingIntent resultPendingIntent = PendingIntent.getActivity(this.context, requestCode++,
resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);
notificationManager
= (NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, builder.build());
notificationId++;
}
Run Code Online (Sandbox Code Playgroud) notifications android notificationmanager android-notifications
我正在尝试实现 ExoPlayer 的Notification Manager,它运行良好,但我不想显示快退和快进按钮。我检查了文档,但找不到隐藏这些按钮的方法。有什么巧妙的方法可以隐藏它们吗?
这是我的代码
private fun initListener() {
val playerNotificationManager: PlayerNotificationManager
val notificationId = 1234
val mediaDescriptionAdapter = object : PlayerNotificationManager.MediaDescriptionAdapter {
override fun getCurrentSubText(player: Player?): String {
return "Sub text"
}
override fun getCurrentContentTitle(player: Player): String {
return "Title"
}
override fun createCurrentContentIntent(player: Player): PendingIntent? {
return null
}
override fun getCurrentContentText(player: Player): String {
return "ContentText"
}
override fun getCurrentLargeIcon(
player: Player,
callback: PlayerNotificationManager.BitmapCallback
): Bitmap? {
return null
}
}
playerNotificationManager = …Run Code Online (Sandbox Code Playgroud) 我正在制作一个Android应用程序,我想取消所有具有特定标签的通知.
现在,似乎只能通过其id(int id)或它们的id和标签来取消通知.
mNotificationManager.cancel(int id);
要么
mNotificationManager.cancel(String tag,int id);
我想能够取消所有String标签的通知,无论int id.
这可能吗?
我一直在浏览NotificationManagerAPI级别10的android文档中的类,但还没有找到实现它的方法.我也浏览了谷歌,但只找到了如何设置通知实际设置的时间以及如何设置显示Toast通知小部件的时间长度.
我已经设置了FLAG_NO_CLEAR并FLAG_ONGOING_EVENT保持通知图标存在,并在展开通知下拉列表后保持通知可见.
我试图在通知栏中显示通知的文本10秒而不是标准时间.所以我基本上想要完成该setDuration(int)功能在Toast小部件中的功能.
我想知道这是否可能,如果有的话,如果有人能指出我正确的方向如何实现它.