notification(通知)的使用
来源:互联网 发布:linux找工作 编辑:程序博客网 时间:2024/06/02 11:18
http://blog.csdn.net/vipzjyno1/article/details/25248021
http://blog.csdn.net/xxbs2003/article/details/19167331
private Notification.Builder mTetheredNotificationBuilder; private void showTetheredNotification(int icon,String type){ synchronized(Tethering.this.mNotificationSync){ NotificationManager notificationManager= (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); if(notificationManager==null){ return; } WifiManager mgr=(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE); if(mgr==null){ return; } if(mLastNotificationId!=0){ if(mLastNotificationId==icon){ return; } notificationManager.cancelAsUser(null,mLastNotificationId, UserHandle.ALL);//就是cancel掉notification mLastNotificationId=0; } Intent intent=new Intent(); if(isBspPackage){ intent.setClassName("com.android.settings",com.android.settings.TetherSettings); }else{ if("wifi".eqauls(type)){ intent.setClassName("com.android.settings", "com.android.settings.wifi.hotspot.TetherWifiSettings"); }else{ intent.setClassName("com.android.settings", "com.android.settings.TetherSettings"); } } intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); //FLAG_ACTIVITY_NO_HISTORY参数的意义:跳转到的Activity不压入栈中 PendingIntent pi=PendingIntent.getActivityAsUser(mContext,0,intent,0, null,UserHandle.CURRENT); Resources r=Resources.getSystem(); CharSequence title=r.getText(com.android.internal.R.string.tethered_notification_title); String message=null; String message_1=null; String message_2=null; if(isBspPackage()){ message=r.getString(com.android.internal.R.string.tethered_notification_message); }else{ if("wifi".equals(type)||"comb".equals(type)){ List<HotspotClient> clients=mgr.getHotspotClients(); int connected=0; int blocked=0; if(clients!=null){ for(HotspotClient client:clients){ if(client.isBlocked){ blocked++; } } connected=clients.size()-blocked; } message=r.getString(com.mediatek.internal.R.string.tethered_notification_message_for_hotspot,connected,blocked); }else{ message=r.getString(com.android.internal.R.string.tethered_notification_message); } } message_1=message; boolean enable=Settings.Secure.getInt(mContent.getContentResolver(), Settings.Secure.INTERFACE_THROTTLE,0)==1; if(enable&&("wifi".equals(type)||"comb".equals(type))){ message_2=r.getString(com.mediatek.internal.R.string.tethered_notification_message_bandwidth_set); message=message_1+", "+message_2; if(mTetheredNotificationBuilder==null){ mTetheredNotificationBuilder=new Notification.Builder(mContext); mTetheredNotificationBuilder.setWhen(0) .setOngoing(true) .setColor(mContext.getColor( com.android.internal.R.color.sytem_notification_accent_color)) .setVisibility(Notification.VISIBILITY_PUBLIC) .setCategory(Notification.CATEGORY_STATUS); } mTetheredNotificationBuilder.setSmallIcon(icon) .setContentTitle(title) .setContentText(message) .setContentIntent(pi); mLastNotificationId=icon; Notification.InboxStyle style=new Notification.InboxStyle(mTetheredNotificationBuilder).addLine(message_1); if(message_2!=null){ style.addLine(message_2); } notificationManager.notifyAsUser(null,mLastNotificationId, style.build(),UserHandle.ALL); } } private void updateTetheredNotification(){ synchronized(mPublicSync){ boolean wifiTethered=false; Set ifaces=mIfaces.keySet(); for(Object iface:ifaces){ TetherInterfaceSM sm=mIfaces.get(iface); if(sm!=null && sm.isTethered() && isWifi((String)iface)){ wifiTethered=true; } } if(!wifiTethered) { return; } } synchronized(Tethering.this.mNotificationSync){ NotificationManager notificationManager=(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); if(notificationManager==null || mgr==null || mTetheredNotificationBuilder==null){ return; } List<HotspotClient> clients=mgr.getHotspotClients(); int connected=0; int blocked=0; if(client!=null){ for(HotspotClient client:clients){ if(client.isBlocked){ blocked++; } } connected=clients.size()-blocked; } Resources r=Resources.getSystem(); CharSequence title=r.getText(com.android.internal.R.string.tethered_notification_title); String message=null; if(isBspPackage()){ message=r.getString(com.android.internal.R.string.tethered_notification_message); }else{ message=r.getString(com.android.internal.R.string.tethered_notification_message_for_hotsport); } String message_1=message; String message_2=null; boolean enable=Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.INTERFACE_THROTTLE,0)==1; if(enable){ message_2=r.getString(com.android.internal.R.string.tethered_notification_message_bandwidth_set); message=message_1+", "+message_2; } mTetheredNotificationBuilder.setContentTitle(title) .setContentText(message); Notification.InboxStyle style=new Notification.InboxStyle(mTetheredNotificationBuilder).addLine(message_1); if(message_2!=null){ style.addLine(message_2); } notificationManager.notify(null,mLastNotificationId, style.build(),UserHandle.ALL); } } private void clearTetheredNotification(){ synchronized(Tethering.this.mNotificationSync){ NotificationManager notificationManager=(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); if(notificationManager!=null && mLastNotificationId!=0){ notificationManager.cancelAsUser(null,mLastNotificationId, UserHandle.ALL); } } } }
0 0
- NOtification(通知)的使用
- notification(通知)的使用
- notification(通知)的使用
- Notification通知的使用
- 使用通知(Notification)
- Android的通知(Notification)使用详解
- android 通知的使用(Notification)
- Android的通知(Notification)使用详解
- Android通知Notification的使用(一)
- Android 通知(Notification)的使用
- Android的通知(Notification)使用详解
- 通知栏(Notification)的基本使用
- Notification通知栏的使用
- android通知(Notification)的使用
- Notification通知栏的使用
- android Notification(通知) 的使用
- Notification(通知)的简单使用
- Notification(通知)的使用简介
- Cocos2d-js 自定义一个功能相对完备的按钮控件
- 常用的正则
- 关于js的仿微信表情包
- LR_参数设置和VSUER关系
- rpmbuild编译一个软件时如何加入自己的补丁patch
- notification(通知)的使用
- Bloom Filter的关键公式
- java 常用集合list与Set、Map区别及适用场景总结
- linux下gcc/g++的命令和使用详解
- jsp页面中如何使用超链接
- 如何写好高考英语作文
- 合并排序的思想与实现
- gdb+gdbserver跨平台调试
- 2014年第五届蓝桥杯C/C++程序设计本科B组省赛 切面条(结果填空)