Skip to content

Commit

Permalink
适配android 8.0通知
Browse files Browse the repository at this point in the history
  • Loading branch information
WVector committed Mar 30, 2018
1 parent 234d05f commit c3c5eaa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

```gradle
dependencies {
compile 'com.qianwen:update-app:3.3.8'
compile 'com.qianwen:update-app:3.3.9'
}
```

Expand All @@ -61,7 +61,7 @@ dependencies {

```gradle
dependencies {
compile 'com.qianwen:update-app-kotlin:1.1.0'
compile 'com.qianwen:update-app-kotlin:1.1.1'
}
```

Expand Down Expand Up @@ -101,6 +101,11 @@ dependencies {
## 更新日志

kotlin版本是依赖java版本的,所以java版本的问题kotlin自然修复
v3.3.9

1,适配android8.0的通知和安装未知来源的app

感谢[typ0520](https://github.com/typ0520)对项目的维护

v3.3.8

Expand Down
Binary file modified apk/app-debug.apk
Binary file not shown.
10 changes: 5 additions & 5 deletions update-app-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.novoda.bintray-release'//添加
android {
compileSdkVersion 25
compileSdkVersion 26
buildToolsVersion "26.0.0"

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -35,15 +35,15 @@ dependencies {

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

//compile 'com.qianwen:update-app:+'
compile project(':update-app')
compile 'com.qianwen:update-app:3.3.9'
// compile project(':update-app')
}
//添加
publish {
userOrg = 'qianwen'//bintray.com用户名
groupId = 'com.qianwen'//jcenter上的路径
artifactId = 'update-app-kotlin'//项目名称
publishVersion = '1.1.0'//版本号
publishVersion = '1.1.1'//版本号
desc = 'a library for android version update'
website = 'https://github.com/WVector/AppUpdate'
}
Expand Down
8 changes: 4 additions & 4 deletions update-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {
compileSdkVersion 25
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -31,7 +31,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
provided 'com.android.support:appcompat-v7:25.3.1'
provided 'com.android.support:appcompat-v7:26.1.0'
testCompile 'junit:junit:4.12'
}

Expand All @@ -40,7 +40,7 @@ publish {
userOrg = 'qianwen'//bintray.com用户名
groupId = 'com.qianwen'//jcenter上的路径
artifactId = 'update-app'//项目名称
publishVersion = '3.3.8'//版本号
publishVersion = '3.3.9'//版本号
desc = 'a library for android version update'
website = 'https://github.com/WVector/AppUpdate'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vector.update_app.service;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
Expand Down Expand Up @@ -29,6 +30,9 @@ public class DownloadService extends Service {

private static final int NOTIFY_ID = 0;
private static final String TAG = DownloadService.class.getSimpleName();
private static final String CHANNEL_ID = "app_update_id";
private static final CharSequence CHANNEL_NAME = "app_update_channel";

public static boolean isRunning = false;
private NotificationManager mNotificationManager;
private DownloadBinder binder = new DownloadBinder();
Expand Down Expand Up @@ -77,7 +81,24 @@ private void setUpNotification() {
return;
}

mBuilder = new NotificationCompat.Builder(this);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
//设置绕过免打扰模式
// channel.setBypassDnd(true);
// //检测是否绕过免打扰模式
// channel.canBypassDnd();
// //设置在锁屏界面上显示这条通知
// channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
// channel.setLightColor(Color.GREEN);
// channel.setShowBadge(true);
// channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
// channel.enableVibration(true);
mNotificationManager.createNotificationChannel(channel);
}


mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
mBuilder.setContentTitle("开始下载")
.setContentText("正在连接服务器")
.setSmallIcon(R.mipmap.lib_update_app_update_icon)
Expand Down

0 comments on commit c3c5eaa

Please sign in to comment.