关于android通知栏图标自定义问题
来源:互联网 发布:php array split 编辑:程序博客网 时间:2024/04/28 13:53
用RemoteView自定义布局很简单的能实现通知栏的图标自定义。可是因为项目需求不能用xml布局,只能用代码写。也没想到怎么用Java代码实现RemoteView布局。然后想到了如下方法:
Class<?> localClass = Class.forName("com.android.internal.R$id");// int = localClass.getField("title").getInt(localClass);// n = localClass.getField("text").getInt(localClass);int iconID = localClass.getField("icon").getInt(localClass);int icon = mContext.getApplicationInfo().icon;Intent notificationIntent = new Intent(mContext, KongActivity.class);Bundle bundle = this.mAdvData.convertToBundle();notificationIntent.putExtras(bundle);notificationIntent.putExtra(KongActivity.STRING_ACTION,AdvAnalysis.ID_NOTIFICATION);notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);// notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);PendingIntent contentIntent = PendingIntent.getActivity(mContext,(int) System.currentTimeMillis(), notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);Notification notification = new Notification(icon,this.mAdvData.getAdvTitle(), System.currentTimeMillis());notification.flags |= Notification.FLAG_AUTO_CANCEL;notification.defaults |= Notification.DEFAULT_LIGHTS;notification.setLatestEventInfo(mContext,this.mAdvData.getAdvTitle(), this.mAdvData.getAdvContent(),contentIntent);Bitmap iconBitmap = Tools.getLocalBitmap(String_iconPath);if (iconBitmap != null) {notification.contentView.setImageViewBitmap(iconID, iconBitmap);}NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService("notification");mNotificationManager.notify(this.INT_NOTIFIID, notification);
最主要的就是这个iconID。用这个可以给notification的icon赋值。
还有就是Intent.FLAG_ACTIVITY_CLEAR_TASK。如果主程序为退出(就是用home退的软件)的时候点击通知栏会带出应用。加上这个Flag可以避免这种情情况。什么原因我这儿不细说了。可以Google下。
0 0
- 关于android通知栏图标自定义问题
- android 自定义通知栏遇到的问题
- android 如何自定义通知栏图标(不使用自定义布局情况下)
- android 如何自定义通知栏图标(不使用自定义布局情况下)
- android 如何自定义通知栏图标(不使用自定义布局情况下)
- Android 通知栏图标 变形解决
- android 通知栏图标变白色方格
- Android通知栏图标空白情况
- [android]JPush自定义通知栏
- Android自定义布局通知栏
- [android]JPush自定义通知栏
- Android极光推送自定义通知问题
- android常用通知管理、自定义通知图标的两种方法
- 坑!!关于通知栏中支持自定义布局,不支持自定义控件的问题
- Android Notification使用系统通知栏布局出现的图标问题
- 关于android语言切换后通知栏显示的问题
- 关于android语言切换后通知栏显示的问题
- 关于UILocalNotification 的soundName问题(通知的自定义声音问题)
- Hadoop学习之Hadoop集群的定制配置(一)
- JQuery常用选择器总结
- Hbase简介
- Java中的ReentrantLock和synchronized两种锁定机制的对比
- mysql函数应用实例:截取身份证中的生日
- 关于android通知栏图标自定义问题
- 重建eclipse的问题
- 数据生成器
- 在Ubuntu 12.04上 Hadoop源代码重新编译
- 4.9Bootstrap学习js插件篇之折叠
- 升级后,常常遇到的遇到的警告、错误,解决方法
- 转:关于const指针的问题
- IOS , plist 配置项说明
- Parentheses Balance uva