Skip to content

Commit

Permalink
完善通知栏封装库
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchong211 committed Nov 22, 2018
1 parent 3160b34 commit 70539aa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@
### 02.使用方法介绍
- 2.0 如何使用该库
```
compile 'cn.yc:notificationLib:1.0.0'
compile 'cn.yc:notificationLib:1.0.2'
```
- 2.1 最简单调用方式
```
Expand Down Expand Up @@ -81,6 +81,14 @@ public void sendNotification(int notifyId, String title, String content , int ic
}
}
```
- 2.4 如果你想获取Notification对象,自己发送消息也可以
```
NotificationUtils notificationUtils = new NotificationUtils(this);
notificationUtils.setContent(getRemoteViews());
Notification notification = notificationUtils.getNotification("这个是标题4", "这个是内容4", R.mipmap.ic_launcher);
notificationUtils.getManager().notify(4,notification);
```


### 04.图片展示
- ![image](https://github.com/yangchong211/YCNotification/blob/master/image/1.png)
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -22,6 +22,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'cn.yc:notificationLib:1.0.0'
compile 'cn.yc:notificationLib:1.0.2'
//compile project(path: ':notificationLib')
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/yc/cn/ycnotification/MainActivity.java
Expand Up @@ -210,7 +210,8 @@ private void sendNotification3() {
private void sendNotification4() {
NotificationUtils notificationUtils = new NotificationUtils(this);
notificationUtils.setContent(getRemoteViews());
notificationUtils.sendNotification(4,"这个是标题4", "这个是内容4", R.mipmap.ic_launcher);
Notification notification = notificationUtils.getNotification("这个是标题4", "这个是内容4", R.mipmap.ic_launcher);
notificationUtils.getManager().notify(4,notification);
}


Expand Down
2 changes: 1 addition & 1 deletion notificationLib/build.gradle
Expand Up @@ -40,7 +40,7 @@ group = "cn.yc"
//发布到JCenter上的项目名字,必须填写
def libName = "YCNotificationLib"
// 版本号,下次更新是只需要更改版本号即可
version = "1.0.0"
version = "1.0.2"
/** 上面配置后上传至jcenter后的编译路径是这样的: compile 'cn.yc:YCBannerLib:1.0' **/

//生成源文件
Expand Down
Expand Up @@ -84,6 +84,30 @@ public void clearNotification(){
getManager().cancelAll();
}

/**
* 获取Notification
* @param title title
* @param content content
*/
public Notification getNotification(String title, String content , int icon){
Notification build;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//android 8.0以上需要特殊处理,也就是targetSDKVersion为26以上
//通知用到NotificationCompat()这个V4库中的方法。但是在实际使用时发现书上的代码已经过时并且Android8.0已经不支持这种写法
Notification.Builder builder = getChannelNotification(title, content, icon);
build = builder.build();
} else {
NotificationCompat.Builder builder = getNotificationCompat(title, content, icon);
build = builder.build();
}
if (flags!=null && flags.length>0){
for (int a=0 ; a<flags.length ; a++){
build.flags |= flags[a];
}
}
return build;
}

/**
* 建议使用这个发送通知
* 调用该方法可以发送通知
Expand Down

0 comments on commit 70539aa

Please sign in to comment.