当前位置: 首页 > news >正文

商城型网站建设/简易的旅游网页制作

商城型网站建设,简易的旅游网页制作,做网站诱导充值犯法吗,网站架构演变流程上面这张图,将具有形同形态,相同表现形式的通知渠道A ,通知渠道B归纳到了同一个渠道组中。通知渠道的引入可以很方便的管理,和归纳同一种类型的通知Notification.通知渠道组的引入同样可以方便的管理,归纳同一种类型的…

AAffA0nNPuCLAAAAAElFTkSuQmCC

上面这张图,将具有形同形态,相同表现形式的通知渠道A ,通知渠道B归纳到了同一个渠道组中。

通知渠道的引入可以很方便的管理,和归纳同一种类型的通知Notification.

通知渠道组的引入同样可以方便的管理,归纳同一种类型的通知渠道Channel.

1.首先看一下Android8.0之前的普通Notification的样式以及使用姿势

AAffA0nNPuCLAAAAAElFTkSuQmCC

可以看到是多个通知 ,无论是不是同一个应用的通知,逐个排列下来,占满了屏幕,不太友好

接下来我们来看一下代码

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)

.setSmallIcon(android.R.drawable.stat_notify_chat)

.setContentTitle("你有一条新的消息")

.setContentText("this is normal notification style")

.setTicker("notification ticker")

.setPriority(1000)

.setAutoCancel(true)

.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})

.setNumber(3)

.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)

.setContentIntent(pendingResult)

.setOngoing(true);

Notification notification = mBuilder.build();

getNotificationManager().notify(notifyId, notification);

2.再来看一下带下载进度的通知栏Notification

AAffA0nNPuCLAAAAAElFTkSuQmCC

起一个线程来模拟 下载进度,间隔1秒更新一下 通知进度。

final NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);

mBuilder.setContentTitle("Picture Download")

.setContentText("Download in progress")

.setOngoing(true)

.setVibrate(new long[]{0})

.setSound(null)

.setTicker("notification ticker")

.setDefaults(NotificationCompat.FLAG_LOCAL_ONLY)

.setSmallIcon(android.R.drawable.stat_notify_chat);

new Thread(

new Runnable() {

@Override

public void run() {

int incr;

for (incr = 0; incr <= 100; incr += 5) {

mBuilder.setProgress(100, incr, false);

mBuilder.setSound(null);

mNotifyManager.notify(0, mBuilder.build());

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

}

}

mBuilder.setContentText("Download complete").setProgress(0, 0, false);

mBuilder.setAutoCancel(true);

mBuilder.setOngoing(false);

mNotifyManager.notify(0, mBuilder.build());

}

}

).start();

3.再来看一下自定义布局的Notification

AAffA0nNPuCLAAAAAElFTkSuQmCC

创建一个布局资源,通过RemoteViews来 渲染,同时也绑定了点击事件

RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.remote_custom_notification);

remoteViews.setTextViewText(R.id.title, "Custom Notification---title");

remoteViews.setTextViewText(R.id.content, "Custom Notification---content");

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("image/*");

intent.addCategory(Intent.CATEGORY_OPENABLE);

PendingIntent pendingIntent = PendingIntent.getActivity(this, REQUEST_CODE_NOTIFY, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)

.setSmallIcon(android.R.drawable.stat_notify_chat)

.setContent(remoteViews)

.setTicker("ticker")

.setContentIntent(pendingIntent).build();

getNotificationManager().notify(notifyId, notification);以上【1】【2】【3】就是常用的通知栏Notification的样式和使用姿势

- - -

### 4.下面来看一下Android 8.0上通知渠道NotificationChannel 的应用

![NotificationChannel.png](http://upload-images.jianshu.io/upload_images/2432544-88f3f7a653560051.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

1. 上图可以看到,相同通知渠道的通知已经被合并,而不是一一全部展开。

2. 如果你的项目TargetSDK在26以上,那么你在使用Notification的时候必须指定一个ChannelId,否则当然会报错

3. 下面是Android 8.0上通知渠道NotificationChannel 的使用代码段,注意点需要传入CHANNEL_ID(随意指定),CHANNEL_NAME(随意指定)

NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

channel.setBypassDnd(true); //设置绕过免打扰模式

channel.canBypassDnd(); //检测是否绕过免打扰模式

channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);//设置在锁屏界面上显示这条通知

channel.setDescription("description of this notification");

channel.setLightColor(Color.GREEN);

channel.setName("name of this notification");

channel.setShowBadge(true);

channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});

channel.enableVibration(true);

getNotificationManager().createNotificationChannel(channel);

- - -

### 5.如果要使用通知渠道组NotificationChannelGroup,那么它的样式跟上图一样,使用姿势是下面这样

1. 这里在渠道组NotificationChannelGroup上绑定了两个通知渠道NotificationChannel ,每个渠道下各有一个通知Notification.

getNotificationManager().createNotificationChannelGroup(new NotificationChannelGroup(GROUP_ID, "GROUP_CHANNEL"));

NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

channel.setGroup(GROUP_ID);

channel.setShowBadge(true);

channel.setLightColor(Color.RED);

channel.enableLights(true);

getNotificationManager().createNotificationChannel(channel);

NotificationChannel channel2 = new NotificationChannel(CHANNEL_ID_2, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

channel2.setGroup(GROUP_ID);

channel2.setShowBadge(true);

channel2.setLightColor(Color.RED);

channel2.enableLights(true);

getNotificationManager().createNotificationChannel(channel2);

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("image/*");

intent.addCategory(Intent.CATEGORY_OPENABLE);

PendingIntent pendingResult = PendingIntent.getActivity(this, REQUEST_CODE_NOTIFY, intent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)

.setSmallIcon(android.R.drawable.stat_notify_chat)

.setContentTitle("notification title_9")

.setContentText("notification content_9")

.setPriority(1000)

.setAutoCancel(true)

.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})

.setNumber(3)

.setDefaults(Notification.DEFAULT_LIGHTS)

.setContentIntent(pendingResult)

.setOngoing(true);

NotificationCompat.Builder mBuilder1 = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID_2)

.setSmallIcon(android.R.drawable.stat_notify_chat)

.setContentTitle("notification title_10")

.setContentText("notification content_10")

.setPriority(1000)

.setAutoCancel(true)

.setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400})

.setNumber(15)

.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)

.setContentIntent(pendingResult)

.setOngoing(true);

getNotificationManager().notify(9, mBuilder.build());

getNotificationManager().notify(10, mBuilder1.build());

- - -

### 6.通知渠道的管理

1.删除渠道

getNotificationManager().deleteNotificationChannel(CHANNEL_ID);

2.删除渠道组

getNotificationManager().deleteNotificationChannelGroup(GROUP_ID);

以上便是老版本上使用Notification 和 Android 8.0上通知渠道,渠道组的姿势。

- - -

http://www.jmfq.cn/news/4815199.html

相关文章:

  • 深圳企业高端网站建设/武汉外包seo公司
  • 遵义企业网站建设/平台推广网站
  • 深圳市南山区做网站的小公司/中国企业培训网
  • 做网站的ebay网/最新注册域名查询
  • 网站域名有哪些/百度seo教程
  • 创意网名昵称大全/seo营销技巧培训班
  • 专业的论坛网站建设开发/方象科技专注于什么领域
  • 做PPT不错的网站有哪些/全国seo公司排名
  • 广州 企业网站建设/哪些网站可以发广告
  • 男人互做网站/黑科技推广软件
  • apache添加多个网站/公司品牌营销策划
  • 做网站公司哪家好/计算机编程培训学校哪家好
  • 影视cms哪个好/郑州网站优化外包顾问
  • 甘肃兰州网站建设/hs网站推广
  • 用java做网站可以/关键词优化排名用什么软件比较好
  • 沈阳网站建设优化企业/学校教育培训机构
  • 软文自助发稿软件开发 网站建设/百度推广系统营销平台
  • 做网站怎么导入地图/百度竞价广告怎么投放
  • 网站建设行业背景/谷歌推广平台
  • 公司只有一个设计师/优化网站排名解析推广
  • 网站建设seo运营规划/微信引流推广怎么找平台
  • 专门做游戏的网站/中国站长之家域名查询
  • ip地址做网站/河南网站定制
  • 结合实际/浙江seo技术培训
  • c网站开发源代码/哪家竞价托管专业
  • 大型平台网站开发/app推广软文范文
  • 韩国唯美网站设计/seo排名分析
  • 移动互联网开发技术学什么/seo查询是什么意思
  • 哪些网站专门做动漫的/郑州官网网站推广优化公司
  • 现在有男的做外围女网站客服吗/网络营销服务公司