forked from alibaba/ARouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Javadoc can not recognize kotlin file for now
- Loading branch information
Showing
4 changed files
with
51 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
arouter-api/src/main/java/com/alibaba/android/arouter/utils/PackageUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.alibaba.android.arouter.utils; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
|
||
import static com.alibaba.android.arouter.launcher.ARouter.logger; | ||
import static com.alibaba.android.arouter.utils.Consts.AROUTER_SP_CACHE_KEY; | ||
import static com.alibaba.android.arouter.utils.Consts.LAST_VERSION_CODE; | ||
import static com.alibaba.android.arouter.utils.Consts.LAST_VERSION_NAME; | ||
|
||
/** | ||
* Android package utils | ||
* | ||
* @author zhilong <a href="mailto:[email protected]">Contact me.</a> | ||
* @version 1.0 | ||
* @since 2017/8/8 下午8:19 | ||
*/ | ||
public class PackageUtils { | ||
public static boolean isNewVersion(Context context) { | ||
PackageInfo packageInfo = getPackageInfo(context); | ||
if (null != packageInfo) { | ||
String versionName = packageInfo.versionName; | ||
int versionCode = packageInfo.versionCode; | ||
|
||
SharedPreferences sp = context.getSharedPreferences(AROUTER_SP_CACHE_KEY, Context.MODE_PRIVATE); | ||
if (!versionName.equals(sp.getString(LAST_VERSION_NAME, null)) || versionCode != sp.getInt(LAST_VERSION_CODE, -1)) { | ||
// new version | ||
sp.edit().putString(LAST_VERSION_NAME, versionName).putInt(LAST_VERSION_CODE, versionCode).apply(); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
public static PackageInfo getPackageInfo(Context context) { | ||
PackageInfo packageInfo = null; | ||
try { | ||
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_CONFIGURATIONS); | ||
} catch (Exception ex) { | ||
logger.error(Consts.TAG, "Get package info error."); | ||
} | ||
|
||
return packageInfo; | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
arouter-api/src/main/java/com/alibaba/android/arouter/utils/PackageUtils.kt
This file was deleted.
Oops, something went wrong.