Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ allprojects {
}
}

`SNAPSHOT`
dependencies {
compile 'com.github.yaming116:UpdateApp:1.0.4-SNAPSHOT'
}


dependencies {
compile 'com.github.yaming116:UpdateApp:1.0.4'
compile 'com.github.yaming116:UpdateApp:1.0.5'
}
```

Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 27
buildToolsVersion "27.0.1"

defaultConfig {
applicationId "me.shenfan.updateapp.sample"
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ buildscript {
allprojects {
repositories {
maven { url "https://www.jitpack.io" }
maven {url "https://dl.google.com/dl/android/maven2/"}
jcenter()
}
}
Expand Down
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion "25.0.1"

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 26
versionCode 3
versionName "1.0.4"
}
Expand All @@ -25,5 +25,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-core-utils:25.3.1'
provided 'com.android.support:support-core-utils:25.3.1'
}
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;
}
}


}
24 changes: 21 additions & 3 deletions library/src/main/java/me/shenfan/updateapp/UpdateService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.shenfan.updateapp;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
Expand All @@ -10,14 +12,15 @@
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Build;
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 @@ -91,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 @@ -271,9 +274,23 @@ private void sendLocalBroadcast(int status, int progress) {
localBroadcastManager.sendBroadcast(localIntent);
}

@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";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(String.valueOf(notifyId), name, importance);
mChannel.setDescription(Description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.BLUE);
mChannel.enableVibration(true);
mChannel.setShowBadge(false);
manager.createNotificationChannel(mChannel);
builder.setChannelId(String.valueOf(notifyId));
}
builder.setContentTitle(getString(R.string.update_app_model_prepare, appName))
.setWhen(System.currentTimeMillis())
.setProgress(100, 1, false)
Expand All @@ -285,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