android - 为什么 bigText 不返回 Style 类型
问题描述
为什么 bigText() 方法不会在 setStyle 中返回 Style 类型,或者为什么 setStyle 需要 Style Type ?
看图片
https://drive.google.com/open?id=1BRYjh4OQp83-VcFmcRjXQpU798asu-16
我正在尝试发出通知
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "kdfjds", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(notificationChannel);
}
Notification.Builder notification = new Notification.Builder(this);
notification.setSmallIcon(R.drawable.ic_launcher_foreground);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_background);
notification.setLargeIcon(largeIcon);
notification.setContentTitle("order");
notification.setContentText("You have new order");
Intent goToOrder = new Intent(this,MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,97,goToOrder,0);
notification.setContentIntent(pendingIntent);
notification.setStyle(new NotificationCompat.BigTextStyle().bigText(this.getString(R.string.charging_reminder_notification_title)));
notification.setAutoCancel(true);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notification.setPriority(Notification.PRIORITY_HIGH);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notificationManager.notify(NOTIFICATION_ID,notification.build());
}
解决方案
尝试使用Notification.BigTextStyle()
而不是NotificationCompat.BigTextStyle()
.
PS - 这里的问题是您正在尝试混合软件包,您实际上是在尝试android.support.v4.app.NotificationCompat.BigTextStyle
在android.app.Notification.Style
预期的时间使用。
推荐阅读
- azure-ad-graph-api - 一旦通过 Azure AD B2B api 发送邀请,如何设置来宾用户的hireDate 属性?
- javascript - Node.js 中的 Ruby Rails .inject 等效项
- r - Travis CI 在 pkg-config 搜索路径中找不到包
- wordpress - 如何添加远程代码以防止代码分发
- java - java中动态创建的order by子句在Vercode扫描中显示为sql注入问题
- capl - 从 CAPL 中的字符串动态分配信号名称
- reactjs - 是的,使用 FieldsArray、ReactJS、redux-from 进行验证
- html - 将图像从数据库嵌入到 HTML
- node.js - res.write() 后重定向页面
- java - 使用 cassandra 数据库查询作为 Flink 程序的源