Skip to content

Commit

Permalink
添加localNotificationCompat依赖v4 25版本,兼容8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yaming116 committed Mar 8, 2018
1 parent dc3412b commit 7d3d607
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package android.support.v4.app;

import android.app.Notification;
import android.content.Context;
import android.support.annotation.NonNull;

import java.util.ArrayList;

/**
* Created by ucmed on 2018/3/8.
*/
public class LocalNotificationCompat extends NotificationCompat {
public static class Builder extends NotificationCompat.Builder{
String mChannelId;
/**
* Constructor.
*
* Automatically sets the when field to {@link System#currentTimeMillis()
* System.currentTimeMillis()} and the audio stream to the
* {@link Notification#STREAM_DEFAULT}.
*
* @param context A {@link Context} that will be used to construct the
* RemoteViews. The Context will not be held past the lifetime of this
* Builder object.
* @param channelId The constructed Notification will be posted on this
* NotificationChannel.
*/
public Builder(@NonNull Context context, @NonNull String channelId) {
super(context);
mContext = context;
mChannelId = channelId;

// Set defaults to match the defaults of a Notification
mNotification.when = System.currentTimeMillis();
mNotification.audioStreamType = Notification.STREAM_DEFAULT;
mPriority = PRIORITY_DEFAULT;
mPeople = new ArrayList<String>();
}

/**
* @deprecated use {@link #LocalNotificationCompat.Builder(Context,String)} instead.
* All posted Notifications must specify a NotificationChannel Id.
*/
@Deprecated
public Builder(Context context) {
this(context, null);
}


/**
* Specifies the channel the notification should be delivered on.
*
* No-op on versions prior to {@link android.os.Build.VERSION_CODES#O} .
*/
public Builder setChannelId(@NonNull String channelId) {
mChannelId = channelId;
return this;
}
}


}
7 changes: 4 additions & 3 deletions library/src/main/java/me/shenfan/updateapp/UpdateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import android.os.Environment;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.LocalNotificationCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
Expand Down Expand Up @@ -94,7 +94,7 @@ public void setUpdateProgressListener(UpdateProgressListener listener) {

private boolean startDownload;//开始下载
private int lastProgressNumber;
private NotificationCompat.Builder builder;
private LocalNotificationCompat.Builder builder;
private NotificationManager manager;
private int notifyId;
private String appName;
Expand Down Expand Up @@ -277,7 +277,7 @@ private void sendLocalBroadcast(int status, int progress) {
@TargetApi(26)
private void buildNotification() {
manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
builder = new NotificationCompat.Builder(this);
builder = new LocalNotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
CharSequence name = "update_channel";
String Description = "zhuojian update channel";
Expand All @@ -302,6 +302,7 @@ private void buildNotification() {
manager.notify(notifyId, builder.build());
}


private void start() {
builder.setContentTitle(appName);
builder.setContentText(getString(R.string.update_app_model_progress, 1, "%"));
Expand Down

0 comments on commit 7d3d607

Please sign in to comment.