自定义通知Remoteviews踩坑
来源:互联网 发布:js如何获取自定义属性 编辑:程序博客网 时间:2024/06/07 02:39
/** * 更新通知栏 */ private void updateNotification(String title) { if (null == mNotificationBuilder) { mNotificationBuilder = new android.support.v4.app.NotificationCompat.Builder(context); mNotificationBuilder.setSmallIcon(R.drawable.hro_logo); mNotificationBuilder.setDefaults(Notification.DEFAULT_LIGHTS); mNotificationBuilder.setOngoing(false); mNotificationBuilder.setWhen(System.currentTimeMillis()); PendingIntent intent = PendingIntent.getActivity(context, 0, new Intent(context, LocalAttachmentFragment.class), PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mNotificationBuilder.setFullScreenIntent(intent, false);// 横幅 } mNotificationBuilder.setContentIntent(intent); remoteViews = new RemoteViews(context.getPackageName(), R.layout.common_notice_text); remoteViews.setTextViewText(R.id.item_content_title, context.getResources().getString(R.string.app_name)); SimpleDateFormat format = new SimpleDateFormat("HH:mm"); remoteViews.setTextViewText(R.id.item_content_time, format.format(new Date(System.currentTimeMillis()))); remoteViews.setImageViewResource(R.id.item_content_logo, R.drawable.hro_logo); remoteViews.setOnClickPendingIntent(R.id.cell_view, intent); mNotificationBuilder.setContent(remoteViews); remoteViews.setTextViewText(R.id.item_content_text, title); // NotificationManager mManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mManager.notify(1, mNotificationBuilder.build()); } }
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/cell_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:orientation="horizontal"> <ImageView android:id="@+id/item_content_logo" android:layout_width="@dimen/horizontal_spacing48" android:layout_height="@dimen/horizontal_spacing48" android:layout_gravity="center_vertical" android:layout_marginLeft="@dimen/common_size_10" android:layout_marginRight="@dimen/common_size_10" android:scaleType="fitCenter" android:src="@drawable/hro_logo" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:orientation="horizontal"> <TextView android:id="@+id/item_content_title" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="标题" style="@style/NotificationTitle" /> <TextView android:id="@+id/item_content_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginRight="@dimen/common_size_15" android:text="通知时间" style="@style/NotificationTitle" /> </LinearLayout> <TextView android:id="@+id/item_content_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="@dimen/common_size_15" android:text="通知内容" style="@style/NotificationInfo" /> </LinearLayout> </LinearLayout></LinearLayout>
写过简单的通知,也自定义过通知,那是很久以前的事了,本以为自己牢牢的掌握了,
时至今日再次遇到类似的坑,我还是浪费了一些时间
这是可以正常运行的,某些情况下会遇到bad notification posted,暂时没有找到解决方法
之所以自定义通知,是因为有的机型不支持设置2行文本内容的通知布局,特此自定义布局,实现通知。
阅读全文
0 0
- 自定义通知Remoteviews踩坑
- RemoteViews自定义通知栏
- RemoteViews 实现简单自定义通知栏
- 使用RemoteViews自定义通知栏样式
- 使用RemoteViews自定义通知栏样式 Notification
- RemoteViews实现自定义通知栏结合BroadCastReceiver实现动态交互
- 通过remoteViews自定义Notification通知栏的布局
- 通知与 RemoteViews
- Android 通知栏Notification,NotificationManager,RemoteViews使用流程,自定义通知栏样式简介
- 使用RemoteViews自定义Notification
- Picasso入门教程(九)回调,remoteViews,通知
- RemoteViews
- RemoteViews
- RemoteViews
- RemoteViews
- Android之利用RemoteViews自定义Notification
- RemoteViews在桌面小部件和通知栏的使用
- RemoteViews在通知栏和小组件中的应用
- JavaScript中SetInterval与setTimeout使用区别
- spring依赖注入方式
- 9.21腾讯面试题总结
- Python 财经数据接口包TuShare的基本使用
- 子序列求最大和
- 自定义通知Remoteviews踩坑
- python 数据科学
- gradle使用技巧
- JavaScript中的循环
- 小白:html
- 理解这两点,也就理解了paxos协议的精髓
- js基础知识示例3--对多选框操作,输出多选框的个数 fl ch2 p29
- 测试管理--测试的任务安排
- 仿京东项目