Skip to content

Commit 7d3d607

Browse files
committed
添加localNotificationCompat依赖v4 25版本,兼容8.0
1 parent dc3412b commit 7d3d607

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package android.support.v4.app;
2+
3+
import android.app.Notification;
4+
import android.content.Context;
5+
import android.support.annotation.NonNull;
6+
7+
import java.util.ArrayList;
8+
9+
/**
10+
* Created by ucmed on 2018/3/8.
11+
*/
12+
public class LocalNotificationCompat extends NotificationCompat {
13+
public static class Builder extends NotificationCompat.Builder{
14+
String mChannelId;
15+
/**
16+
* Constructor.
17+
*
18+
* Automatically sets the when field to {@link System#currentTimeMillis()
19+
* System.currentTimeMillis()} and the audio stream to the
20+
* {@link Notification#STREAM_DEFAULT}.
21+
*
22+
* @param context A {@link Context} that will be used to construct the
23+
* RemoteViews. The Context will not be held past the lifetime of this
24+
* Builder object.
25+
* @param channelId The constructed Notification will be posted on this
26+
* NotificationChannel.
27+
*/
28+
public Builder(@NonNull Context context, @NonNull String channelId) {
29+
super(context);
30+
mContext = context;
31+
mChannelId = channelId;
32+
33+
// Set defaults to match the defaults of a Notification
34+
mNotification.when = System.currentTimeMillis();
35+
mNotification.audioStreamType = Notification.STREAM_DEFAULT;
36+
mPriority = PRIORITY_DEFAULT;
37+
mPeople = new ArrayList<String>();
38+
}
39+
40+
/**
41+
* @deprecated use {@link #LocalNotificationCompat.Builder(Context,String)} instead.
42+
* All posted Notifications must specify a NotificationChannel Id.
43+
*/
44+
@Deprecated
45+
public Builder(Context context) {
46+
this(context, null);
47+
}
48+
49+
50+
/**
51+
* Specifies the channel the notification should be delivered on.
52+
*
53+
* No-op on versions prior to {@link android.os.Build.VERSION_CODES#O} .
54+
*/
55+
public Builder setChannelId(@NonNull String channelId) {
56+
mChannelId = channelId;
57+
return this;
58+
}
59+
}
60+
61+
62+
}

library/src/main/java/me/shenfan/updateapp/UpdateService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import android.os.Environment;
2121
import android.os.IBinder;
2222
import android.support.annotation.Nullable;
23-
import android.support.v4.app.NotificationCompat;
23+
import android.support.v4.app.LocalNotificationCompat;
2424
import android.support.v4.content.FileProvider;
2525
import android.support.v4.content.LocalBroadcastManager;
2626
import android.text.TextUtils;
@@ -94,7 +94,7 @@ public void setUpdateProgressListener(UpdateProgressListener listener) {
9494

9595
private boolean startDownload;//开始下载
9696
private int lastProgressNumber;
97-
private NotificationCompat.Builder builder;
97+
private LocalNotificationCompat.Builder builder;
9898
private NotificationManager manager;
9999
private int notifyId;
100100
private String appName;
@@ -277,7 +277,7 @@ private void sendLocalBroadcast(int status, int progress) {
277277
@TargetApi(26)
278278
private void buildNotification() {
279279
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
280-
builder = new NotificationCompat.Builder(this);
280+
builder = new LocalNotificationCompat.Builder(this);
281281
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
282282
CharSequence name = "update_channel";
283283
String Description = "zhuojian update channel";
@@ -302,6 +302,7 @@ private void buildNotification() {
302302
manager.notify(notifyId, builder.build());
303303
}
304304

305+
305306
private void start() {
306307
builder.setContentTitle(appName);
307308
builder.setContentText(getString(R.string.update_app_model_progress, 1, "%"));

0 commit comments

Comments
 (0)