diff --git a/README.md b/README.md index 32c1f77..19943cf 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,27 @@ # pgyer-android-app-update -A light-weighted library which can update android app by pgyer app store. +A light-weighted library which can update android app by pgyer App Store. -## step 1: +[Download Demo](https://www.pgyer.com/android_app_update) + +## 1.Usage + +### step 1: add below code in your app *AndroidManifest.xml* file. ``` - - - - + + + + ``` -## step 2: +### step 2: ``` implementation 'com.xsir:PgyerAndroidAppUpdate:' @@ -33,6 +37,18 @@ In MainActivity onCreate() method: PgyerApi.checkUpdate(this); ``` +## 2.Update Log + +### v0.9.4 + +- 自定义 FileProvider 防止和集成 app 的 FileProvider 冲突; +- 保证 FileProvider authorities 的唯一性; +- 抽取几个常量类和工具类; + +## TODO + +// TODO: 2019/3/20 使用构建者模式增加更新参数配置,使用线程池 + ## LICENSE [Apache2.0](https://github.com/xinpengfei520/pgyer-android-app-update/blob/master/LICENSE) \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index df903f7..ee66560 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.xsir.pgyerappupdate" minSdkVersion versions.minSdkVersion targetSdkVersion versions.targetSdkVersion - versionCode 10 - versionName "1.9" + versionCode 11 + versionName "1.9.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -61,8 +61,8 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - //implementation project(':library') - implementation 'com.xsir:PgyerAndroidAppUpdate:0.9' + implementation project(':library') + //implementation 'com.xsir:PgyerAndroidAppUpdate:0.9' } def getApkFullPath() { @@ -91,7 +91,7 @@ def readProperties(key) { } static def getUpdateDescription() { - return '1.发布V0.9版本库;\n2.修复一些bug;\n3.提升用户体验!' + return '1.发布 V0.9.4 版本库;\n2.修复一些bug;\n3.提升用户体验!' } task("uploadApk") { diff --git a/build.gradle b/build.gradle index 9ca3e3b..ae2b7a1 100644 --- a/build.gradle +++ b/build.gradle @@ -8,8 +8,8 @@ buildscript { 'supportLibrary' : '27.1.1', - 'libReleaseCode' : 12, - 'libReleaseName' : '0.9.3' + 'libReleaseCode' : 13, + 'libReleaseName' : '0.9.4' ] diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 4427e3c..e96f7ad 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -19,8 +19,8 @@ android:windowSoftInputMode="stateHidden|stateAlwaysHidden" /> = Build.VERSION_CODES.N) { - Log.i(TAG, context.getApplicationContext().getPackageName() + SUFFIX_PROVIDER); - Uri uriForFile = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + SUFFIX_PROVIDER, file); - Log.i(TAG, uriForFile.getPath()); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + Uri uriForFile = CustomFileProvider.getUriForFile(context, Constants.AUTHORITY, file); + XLogUtils.i(TAG, "file uri path:" + uriForFile.getPath()); + + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); intent.setDataAndType(uriForFile, context.getContentResolver().getType(uriForFile)); + } else { intent.setDataAndType(Uri.fromFile(file), getMIMEType(file)); } @@ -172,7 +182,7 @@ public void openFile(File file, Context context) { context.startActivity(intent); } catch (Exception e) { e.printStackTrace(); - showShort("没有找到打开此类文件的程序!"); + ToastUtils.showShort(getApplicationContext(), "没有找到打开此类文件的程序!"); } } @@ -189,6 +199,7 @@ public static boolean deleteFileWithPath(String filePath) { if (f.isFile()) { return f.delete(); } + return false; } @@ -196,15 +207,7 @@ public static void startAction(Context context, String url, String apkName) { Intent intent = new Intent(context, DownLoadService.class); intent.putExtra(DOWNLOAD_URL, url); intent.putExtra(APK_NAME, apkName); - Toast.makeText(context, "正在下载中...", Toast.LENGTH_SHORT).show(); context.startService(intent); } - - private void showShort(String message) { - if (!TextUtils.isEmpty(message)) { - Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show(); - } - } - } diff --git a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/AppInfoUtils.java b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/AppInfoUtils.java index a763f5c..32fd0f1 100644 --- a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/AppInfoUtils.java +++ b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/AppInfoUtils.java @@ -3,7 +3,6 @@ import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import android.util.Log; /** * Created by x-sir on 2019/1/3 :) @@ -32,8 +31,9 @@ public static int getVersionCode(Context context) { } } catch (Exception e) { e.printStackTrace(); - Log.e(TAG, "VersionInfo" + "Exception" + e); + XLogUtils.e(TAG, "VersionInfo" + "Exception" + e); } + return versioncode; } @@ -50,10 +50,11 @@ public static String getVersionName(Context context) { .getPackageManager() .getPackageInfo(context.getPackageName(), 0); localVersion = packageInfo.versionName; - Log.d(TAG, "本软件的版本号。。" + localVersion); + XLogUtils.d(TAG, "当前 App 版本号:" + localVersion); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } + return localVersion; } @@ -68,6 +69,7 @@ public static String getPackageName(Context context) { return ""; } Context appContext = context.getApplicationContext(); + return appContext.getPackageName(); } } diff --git a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/HttpClientUtils.java b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/HttpClientUtils.java index 00c866e..3d17ef0 100644 --- a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/HttpClientUtils.java +++ b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/HttpClientUtils.java @@ -1,7 +1,5 @@ package com.xsir.pgyerappupdate.library.utils; -import android.util.Log; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -73,7 +71,7 @@ private static void getRequest(String requestUrl, HttpClientUtils.OnRequestCallB baos.write(bytes, 0, readLen); } String result = baos.toString(); - Log.i(TAG, " result:" + result); + XLogUtils.i(TAG, " result:" + result); message = result; isSuccess = true; @@ -154,7 +152,7 @@ private static void postRequest(String requestUrl, String params, HttpClientUtil baos.write(bytes, 0, readLen); } String backStr = baos.toString(); - Log.i(TAG, "backStr:" + backStr); + XLogUtils.i(TAG, "backStr:" + backStr); message = backStr; isSuccess = true; diff --git a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/ManifestUtils.java b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/ManifestUtils.java index fe2b7c0..c34849b 100644 --- a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/ManifestUtils.java +++ b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/ManifestUtils.java @@ -11,16 +11,6 @@ */ public class ManifestUtils { - /** - * 蒲公英 apiKey - */ - public static final String PGYER_API_KEY = "PGYER_API_KEY"; - /** - * 蒲公英 appKey - */ - public static final String PGYER_APP_KEY = "PGYER_APP_KEY"; - - /** * 根据 meta data 的 name 获取 value * @@ -32,7 +22,9 @@ public static String getMetaDataValueByName(Context context, String key) { if (context == null || TextUtils.isEmpty(key)) { return null; } + String resultData = null; + try { PackageManager packageManager = context.getPackageManager(); if (packageManager != null) { diff --git a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/ToastUtils.java b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/ToastUtils.java new file mode 100644 index 0000000..fc3559e --- /dev/null +++ b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/ToastUtils.java @@ -0,0 +1,42 @@ +package com.xsir.pgyerappupdate.library.utils; + +import android.content.Context; +import android.text.TextUtils; +import android.widget.Toast; + +/** + * Created by x-sir on 2018/7/22 :) + * Function:Toast effect. + */ +public class ToastUtils { + + /** + * show short toast. + * + * @param message show content. + */ + public static void showShort(Context context, String message) { + if (context == null) { + return; + } + + if (!TextUtils.isEmpty(message)) { + Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_SHORT).show(); + } + } + + /** + * show long toast. + * + * @param message show content. + */ + public static void showLong(Context context, String message) { + if (context == null) { + return; + } + + if (!TextUtils.isEmpty(message)) { + Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_LONG).show(); + } + } +} diff --git a/library/src/main/java/com/xsir/pgyerappupdate/library/utils/XLogUtils.java b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/XLogUtils.java new file mode 100644 index 0000000..f04a746 --- /dev/null +++ b/library/src/main/java/com/xsir/pgyerappupdate/library/utils/XLogUtils.java @@ -0,0 +1,77 @@ +package com.xsir.pgyerappupdate.library.utils; + +import android.util.Log; + +/** + * Created by x-sir on 2018-07-20 :) + * Function:日志打印类工具类 + */ +public class XLogUtils { + + private static final String DEFAULT_TAG = "XLogUtils"; + private static boolean IS_NEED_PRINT_LOG = true; + + public static void setIsNeedPrintLog(boolean isNeedPrintLog) { + IS_NEED_PRINT_LOG = isNeedPrintLog; + } + + public static void v(String msg) { + if (IS_NEED_PRINT_LOG) { + Log.v(DEFAULT_TAG, msg); + } + } + + public static void d(String msg) { + if (IS_NEED_PRINT_LOG) { + Log.d(DEFAULT_TAG, msg); + } + } + + public static void i(String msg) { + if (IS_NEED_PRINT_LOG) { + Log.i(DEFAULT_TAG, msg); + } + } + + public static void w(String msg) { + if (IS_NEED_PRINT_LOG) { + Log.w(DEFAULT_TAG, msg); + } + } + + public static void e(String msg) { + if (IS_NEED_PRINT_LOG) { + Log.e(DEFAULT_TAG, msg); + } + } + + public static void i(String tag, String msg) { + if (IS_NEED_PRINT_LOG) { + Log.i(tag, msg); + } + } + + public static void w(String tag, String msg) { + if (IS_NEED_PRINT_LOG) { + Log.w(tag, msg); + } + } + + public static void e(String tag, String msg) { + if (IS_NEED_PRINT_LOG) { + Log.e(tag, msg); + } + } + + public static void v(String tag, String msg) { + if (IS_NEED_PRINT_LOG) { + Log.v(tag, msg); + } + } + + public static void d(String tag, String msg) { + if (IS_NEED_PRINT_LOG) { + Log.d(tag, msg); + } + } +} diff --git a/library/src/main/res/xml/file_paths.xml b/library/src/main/res/xml/file_paths.xml index d76ed3a..6b36a4f 100644 --- a/library/src/main/res/xml/file_paths.xml +++ b/library/src/main/res/xml/file_paths.xml @@ -7,26 +7,5 @@ - - - - - - - - - - - \ No newline at end of file