diff --git a/README.md b/README.md index 1ac2a76..c029109 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ ```gradle dependencies { - compile 'com.qianwen:update-app:3.5.2' + implementation 'com.github.szhdev.AppUpdate:update-app:1.0.1' } ``` @@ -61,7 +61,7 @@ dependencies { ```gradle dependencies { - compile 'com.qianwen:update-app-kotlin:1.2.3' + implementation 'com.github.szhdev.AppUpdate:update-app-kotlin:1.0.1' } ``` @@ -104,6 +104,12 @@ dependencies { kotlin版本是依赖java版本的,所以java版本的问题kotlin自然修复 + +1.0.1 + + 1. setStoragePermission(false) //增加是否需要存储权限 配合 setTargetPath(path) 使用。 + + v3.5.2 1,修复下载过程中,关闭对话框不能自动安装问题。 @@ -241,4 +247,4 @@ V3.3.0 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file + limitations under the License. diff --git a/build.gradle b/build.gradle index b397a5c..00411f8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,16 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.1.4' - ext.novoda_version = '0.4.0' + ext.kotlin_version = '1.4.31' + ext.novoda_version = '0.9.2' repositories { + google() + mavenCentral() jcenter() - - maven { - url 'https://maven.google.com/' - name 'Google' - } + maven {url 'https://dl.google.com/dl/android/maven2/'} } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.5.3' classpath "com.novoda:bintray-release:$novoda_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong @@ -21,15 +19,13 @@ buildscript { } allprojects { repositories { + google() jcenter() mavenCentral() // maven{url 'https://dl.bintray.com/qianwen/maven/'} maven { url "https://www.jitpack.io" } - maven { - url 'https://maven.google.com/' - name 'Google' - } + maven {url 'https://dl.google.com/dl/android/maven2/'} } tasks.withType(Javadoc) { options { @@ -47,7 +43,7 @@ ext { //防止上传kotlin是报错, -tasks.getByPath(":update-app-kotlin:releaseAndroidJavadocs").enabled = false +//tasks.getByPath(":update-app-kotlin:releaseAndroidJavadocs").enabled = false task clean(type: Delete) { delete rootProject.buildDir } diff --git a/gradle.properties b/gradle.properties index aac7c9b..68d02dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,3 +15,8 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +systemProp.http.proxyHost=127.0.0.1 +systemProp.http.proxyPort=1080 +systemProp.http.proxyUser=userid +systemProp.http.proxyPassword=password +systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 57180f7..a0f671f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 29d1643..2bab9e3 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,12 +2,11 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' android { - compileSdkVersion 26 - buildToolsVersion "25.0.3" + compileSdkVersion 28 defaultConfig { applicationId "com.vector.appupdatedemo" - minSdkVersion 14 - targetSdkVersion 26 + minSdkVersion 21 + targetSdkVersion 28 versionCode 1 versionName "0.1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -25,31 +24,31 @@ android { dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(include: ['*.jar'], dir: 'libs') + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // compile project(':update-app') - compile project(':update-app-kotlin') + implementation project(':update-app-kotlin') //compile 'com.qianwen:update-app-kotlin:1.1.0' //okgo //rxjava 1 - compile 'com.android.support:palette-v7:26.1.0' + implementation 'com.android.support:palette-v7:28.0.0' //权限引导 - compile 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support:appcompat-v7:28.0.0' - compile 'com.android.support.constraint:constraint-layout:1.0.2' + implementation 'com.android.support.constraint:constraint-layout:2.0.4' - compile 'com.qianwen:okhttp-utils:3.8.0' + implementation 'com.qianwen:okhttp-utils:3.9.5' - compile 'com.lzy.net:okgo:3.0.4' + implementation 'com.lzy.net:okgo:3.0.4' - compile 'io.reactivex:rxjava:1.2.9' + implementation 'io.reactivex:rxjava:1.3.8' - compile 'io.reactivex:rxandroid:1.2.0' - compile 'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar' - testCompile 'junit:junit:4.12' + implementation 'io.reactivex:rxandroid:1.2.1' + implementation 'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar' + testImplementation 'junit:junit:4.13.2' } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 120dfcd..cf530b1 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + xmlns:tools="http://schemas.android.com/tools" + package="com.vector.appupdatedemo"> @@ -14,7 +15,9 @@ android:icon="@mipmap/app_update_logo" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:networkSecurityConfig="@xml/network_security_config" + android:theme="@style/AppTheme" + tools:ignore="UnusedAttribute"> Unit)? = null -) = activity.dialog(title, message, init) +) = activity?.dialog(title, message, init) fun Context.dialog( title: String? = null, @@ -51,7 +51,7 @@ fun Fragment.dialog( @StringRes message: Int, @StringRes title: Int? = null, init: (KAlertDialogBuilder.() -> Unit)? = null -) = activity.dialog(message, title, init) +) = activity?.dialog(message, title, init) fun Context.dialog( @StringRes message: Int, @@ -63,7 +63,7 @@ fun Context.dialog( if (init != null) init() } -fun Fragment.dialog(init: KAlertDialogBuilder.() -> Unit): KAlertDialogBuilder = activity.dialog(init) +fun Fragment.dialog(init: KAlertDialogBuilder.() -> Unit): KAlertDialogBuilder = activity!!.dialog(init) fun Context.dialog(init: KAlertDialogBuilder.() -> Unit) = KAlertDialogBuilder(this).apply { init() } @@ -71,7 +71,7 @@ fun Fragment.progressDialog( @StringRes message: Int? = null, @StringRes title: Int? = null, init: (ProgressDialog.() -> Unit)? = null -) = activity.progressDialog(message, title, init) +) = activity?.progressDialog(message, title, init) fun Context.progressDialog( @StringRes message: Int? = null, @@ -83,7 +83,7 @@ fun Fragment.indeterminateProgressDialog( @StringRes message: Int? = null, @StringRes title: Int? = null, init: (ProgressDialog.() -> Unit)? = null -) = activity.progressDialog(message, title, init) +) = activity?.progressDialog(message, title, init) fun Context.indeterminateProgressDialog( @StringRes message: Int? = null, @@ -95,7 +95,7 @@ fun Fragment.progressDialog( message: String? = null, title: String? = null, init: (ProgressDialog.() -> Unit)? = null -) = activity.progressDialog(message, title, init) +) = activity?.progressDialog(message, title, init) fun Context.progressDialog( message: String? = null, @@ -107,7 +107,7 @@ fun Fragment.indeterminateProgressDialog( message: String? = null, title: String? = null, init: (ProgressDialog.() -> Unit)? = null -) = activity.indeterminateProgressDialog(message, title, init) +) = activity?.indeterminateProgressDialog(message, title, init) fun Context.indeterminateProgressDialog( message: String? = null, @@ -133,7 +133,7 @@ fun Fragment.sheet( title: CharSequence? = null, items: List, onClick: (Int) -> Unit -) = activity.sheet(title, items, onClick) +) = activity?.sheet(title, items, onClick) fun Context.sheet( title: CharSequence? = null, diff --git a/sample/src/main/java/com/vector/appupdatedemo/ui/JavaActivity.java b/sample/src/main/java/com/vector/appupdatedemo/ui/JavaActivity.java index 68ec054..2fb0ea1 100644 --- a/sample/src/main/java/com/vector/appupdatedemo/ui/JavaActivity.java +++ b/sample/src/main/java/com/vector/appupdatedemo/ui/JavaActivity.java @@ -37,7 +37,7 @@ public class JavaActivity extends AppCompatActivity { private static final String TAG = JavaActivity.class.getSimpleName(); - private String mUpdateUrl = "https://raw.githubusercontent.com/WVector/AppUpdateDemo/master/json/json.txt"; + private String mUpdateUrl = "http://rest.apizza.net/mock/ce89c041a1eaa59410f253720f952c0c/update"; private String mUpdateUrl1 = "https://raw.githubusercontent.com/WVector/AppUpdateDemo/master/json/json1.txt"; private boolean isShowDownloadProgress; private String mApkFileUrl = "https://raw.githubusercontent.com/WVector/AppUpdateDemo/master/apk/sample-debug.apk"; @@ -109,7 +109,7 @@ public void constraintUpdate(View view) { //当前Activity .setActivity(this) //更新地址 - .setUpdateUrl(mUpdateUrl1) + .setUpdateUrl(mUpdateUrl) //实现httpManager接口的对象 .setHttpManager(new UpdateAppHttpUtil()) .build() @@ -131,6 +131,7 @@ public void updateDiy(View view) { params.put("key1", "value2"); params.put("key2", "value3"); + final String path = getExternalFilesDir("").getAbsolutePath(); new UpdateAppManager .Builder() @@ -163,7 +164,7 @@ public void onException(Exception e) { //为按钮,进度条设置颜色。 .setThemeColor(0xffffac5d) //设置apk下砸路径,默认是在下载到sd卡下/Download/1.0.0/test.apk -// .setTargetPath(path) + .setTargetPath(path) //设置appKey,默认从AndroidManifest.xml获取,如果,使用自定义参数,则此项无效 // .setAppKey("ab55ce55Ac4bcP408cPb8c1Aaeac179c5f6f") .setUpdateDialogFragmentListener(new IUpdateDialogFragmentListener() { @@ -210,6 +211,8 @@ protected UpdateAppBean parseJson(String json) { .setTargetSize(jsonObject.optString("target_size")) //是否强制更新,可以不设置 .setConstraint(true) + //是否请求读写权限 与 setTargetPath()配合使用 + .setStoragePermission(false) //设置md5,可以不设置 .setNewMd5(jsonObject.optString("new_md5")); } catch (JSONException e) { diff --git a/sample/src/main/java/com/vector/appupdatedemo/ui/MainActivity.java b/sample/src/main/java/com/vector/appupdatedemo/ui/MainActivity.java index 2cec5e3..b207235 100644 --- a/sample/src/main/java/com/vector/appupdatedemo/ui/MainActivity.java +++ b/sample/src/main/java/com/vector/appupdatedemo/ui/MainActivity.java @@ -30,7 +30,7 @@ protected void onCreate(Bundle savedInstanceState) { im.setImageBitmap(AppUpdateUtils.drawableToBitmap(AppUpdateUtils.getAppIcon(this))); - getPermission(); +// getPermission(); } diff --git a/sample/src/main/res/xml/file_paths.xml b/sample/src/main/res/xml/file_paths.xml new file mode 100644 index 0000000..354794b --- /dev/null +++ b/sample/src/main/res/xml/file_paths.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/sample/src/main/res/xml/network_security_config.xml b/sample/src/main/res/xml/network_security_config.xml new file mode 100644 index 0000000..9be597a --- /dev/null +++ b/sample/src/main/res/xml/network_security_config.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/update-app-kotlin/build.gradle b/update-app-kotlin/build.gradle index 210eebe..5ab54b5 100644 --- a/update-app-kotlin/build.gradle +++ b/update-app-kotlin/build.gradle @@ -2,12 +2,11 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'com.novoda.bintray-release'//添加 android { - compileSdkVersion 26 - buildToolsVersion "26.0.0" + compileSdkVersion 28 defaultConfig { - minSdkVersion 14 - targetSdkVersion 26 + minSdkVersion 21 + targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -27,16 +26,16 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + api fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - testCompile 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.2' - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:"+rootProject.kotlin_version - compile 'com.qianwen:update-app:'+rootProject.ext.update_app_version -// compile project(':update-app') +// api 'com.qianwen:update-app:'+rootProject.ext.update_app_version + api project(':update-app') } //添加 publish { diff --git a/update-app/build.gradle b/update-app/build.gradle index d4ad1b0..a80c69b 100644 --- a/update-app/build.gradle +++ b/update-app/build.gradle @@ -1,11 +1,10 @@ apply plugin: 'com.android.library' apply plugin: 'com.novoda.bintray-release'//添加 android { - compileSdkVersion 26 - buildToolsVersion "25.0.3" + compileSdkVersion 28 defaultConfig { - minSdkVersion 14 - targetSdkVersion 26 + minSdkVersion 21 + targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -27,12 +26,12 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + api fileTree(include: ['*.jar'], dir: 'libs') + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - provided 'com.android.support:appcompat-v7:26.1.0' - testCompile 'junit:junit:4.12' + compileOnly 'com.android.support:appcompat-v7:28.0.0' + testImplementation 'junit:junit:4.13.2' } //添加 diff --git a/update-app/src/main/java/com/vector/update_app/UpdateAppBean.java b/update-app/src/main/java/com/vector/update_app/UpdateAppBean.java index 0729b1c..112a008 100644 --- a/update-app/src/main/java/com/vector/update_app/UpdateAppBean.java +++ b/update-app/src/main/java/com/vector/update_app/UpdateAppBean.java @@ -33,6 +33,8 @@ public class UpdateAppBean implements Serializable { private String target_size; //是否强制更新 private boolean constraint; + //是否请求读写权限 + private boolean isPermission = true; //md5 private String new_md5; //是否增量 暂时不用 @@ -58,6 +60,15 @@ public void setHideDialog(boolean hideDialog) { mHideDialog = hideDialog; } + public boolean isPermission() { + return isPermission; + } + + public UpdateAppBean setStoragePermission(boolean permission) { + isPermission = permission; + return this; + } + public boolean isUpdate() { return !TextUtils.isEmpty(this.update) && "Yes".equals(this.update); } diff --git a/update-app/src/main/java/com/vector/update_app/UpdateDialogFragment.java b/update-app/src/main/java/com/vector/update_app/UpdateDialogFragment.java index 5dcbee2..e64ba6c 100644 --- a/update-app/src/main/java/com/vector/update_app/UpdateDialogFragment.java +++ b/update-app/src/main/java/com/vector/update_app/UpdateDialogFragment.java @@ -55,20 +55,7 @@ public class UpdateDialogFragment extends DialogFragment implements View.OnClick private NumberProgressBar mNumberProgressBar; private ImageView mIvClose; private TextView mTitleTextView; - /** - * 回调 - */ - private ServiceConnection conn = new ServiceConnection() { - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - startDownloadApp((DownloadService.DownloadBinder) service); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - } - }; private LinearLayout mLlClose; //默认色 private int mDefaultColor = 0xffe94339; @@ -285,21 +272,23 @@ private void initEvents() { public void onClick(View view) { int i = view.getId(); if (i == R.id.btn_ok) { + if(!mUpdateApp.isPermission()){ + installApp(); + }else { + //权限判断是否有访问外部存储空间权限 + int flag = ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE); + if (flag != PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + // 用户拒绝过这个权限了,应该提示用户,为什么需要这个权限。 + Toast.makeText(getActivity(), TIPS, Toast.LENGTH_LONG).show(); + } else { + // 申请授权。 + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + } - //权限判断是否有访问外部存储空间权限 - int flag = ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE); - if (flag != PackageManager.PERMISSION_GRANTED) { - if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - // 用户拒绝过这个权限了,应该提示用户,为什么需要这个权限。 - Toast.makeText(getActivity(), TIPS, Toast.LENGTH_LONG).show(); } else { - // 申请授权。 - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + installApp(); } - - } else { - installApp(); - } } else if (i == R.id.iv_close) { @@ -354,9 +343,10 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in //升级 installApp(); } else { - //提示,并且关闭 Toast.makeText(getActivity(), TIPS, Toast.LENGTH_LONG).show(); - dismiss(); + if (!mUpdateApp.isConstraint()) { + dismiss(); + } } } @@ -368,7 +358,17 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in */ private void downloadApp() { //使用ApplicationContext延长他的生命周期 - DownloadService.bindService(getActivity().getApplicationContext(), conn); + DownloadService.bindService(getActivity().getApplicationContext(), new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + startDownloadApp((DownloadService.DownloadBinder) service); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + + } + }); } /** @@ -418,8 +418,12 @@ public boolean onFinish(final File file) { @Override public void onError(String msg) { - if (!UpdateDialogFragment.this.isRemoving()) { - dismissAllowingStateLoss(); + if ( mUpdateApp.isConstraint()) { + showErrorBtn(); + }else { + if (!UpdateDialogFragment.this.isRemoving()) { + dismissAllowingStateLoss(); + } } } @@ -456,6 +460,20 @@ public void onClick(View v) { }); } + private void showErrorBtn() { + mNumberProgressBar.setProgress(0); + mNumberProgressBar.setVisibility(View.GONE); + mUpdateOkButton.setText("重新下载"); + mUpdateOkButton.setVisibility(View.VISIBLE); + mUpdateOkButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + installApp(); + } + }); + } + + // @Override // public void onActivityResult(int requestCode, int resultCode, Intent data) {