Skip to content

Commit

Permalink
Merge pull request #77 from weifengzz/MIUtils_branch
Browse files Browse the repository at this point in the history
修改MIUIUtils类中isMIUI方法android 8.0以上异常
  • Loading branch information
wonday authored Mar 22, 2019
2 parents fd22cc7 + 38bf446 commit 065688b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void getDeviceId(final Promise promise) {
@ReactMethod
public void setApplicationIconBadgeNumber(int badgeNumber, final Promise promise) {

if (MIUIUtils.isMIUI()) { //小米特殊处理
if (MIUIUtils.isMIUI(getReactApplicationContext())) { //小米特殊处理
FLog.d(ReactConstants.TAG, "setApplicationIconBadgeNumber for xiaomi");

if (badgeNumber==0) {
Expand Down Expand Up @@ -260,7 +260,7 @@ public void onHostResume() {
public void onHostPause() {

//小米特殊处理, 处于后台时更新角标, 否则会被系统清除,看不到
if (MIUIUtils.isMIUI()) {
if (MIUIUtils.isMIUI(getReactApplicationContext())) {
FLog.d(ReactConstants.TAG, "onHostPause:setBadgeNumber for xiaomi");
MIUIUtils.setBadgeNumber(this.context, getCurrentActivity().getClass(), badgeNumber);
}
Expand All @@ -271,7 +271,7 @@ public void onHostPause() {
public void onHostDestroy() {

//小米特殊处理, 处于后台时更新角标, 否则会被系统清除,看不到
if (MIUIUtils.isMIUI()) {
if (MIUIUtils.isMIUI(getReactApplicationContext())) {
FLog.d(ReactConstants.TAG, "onHostDestroy:setBadgeNumber for xiaomi");
MIUIUtils.setBadgeNumber(this.context, getCurrentActivity().getClass(), badgeNumber);
}
Expand Down
21 changes: 8 additions & 13 deletions android/src/main/java/org/wonday/aliyun/push/MIUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,23 @@ public class MIUIUtils {
private static int notificationId = (int)(System.currentTimeMillis()/1000);


public static boolean isMIUI() {
public static boolean isMIUI(Context context) {
if(hasChecked)
{
return isMIUI;
}

Properties prop= new Properties();

try {
prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
} catch (IOException e)
SystemProperty sp = new SystemProperty(context);
if (sp.getOrThrow(KEY_MIUI_VERSION_CODE) != null || sp.getOrThrow(KEY_MIUI_VERSION_NAME) != null || sp.getOrThrow(KEY_MIUI_INTERNAL_STORAGE) != null) {
hasChecked = true;
isMIUI = true;
}
} catch (Exception e)
{
e.printStackTrace();
return false;
}

isMIUI= prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null
|| prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null
|| prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null;

hasChecked = true;


return isMIUI;
}

Expand Down
34 changes: 34 additions & 0 deletions android/src/main/java/org/wonday/aliyun/push/SystemProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.wonday.aliyun.push;

import android.content.Context;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SystemProperty {
private final Context mContext;

public SystemProperty(Context mContext) {
this.mContext = mContext;
}

public String getOrThrow(String key) throws Exception {
try {
ClassLoader classLoader = mContext.getClassLoader();
Class SystemProperties = classLoader.loadClass("android.os.SystemProperties");
Method methodGet = SystemProperties.getMethod("get", String.class);
return (String) methodGet.invoke(SystemProperties, key);
} catch (Exception e) {
throw new Exception(e);
}
}

public String get(String key) {
try {
return getOrThrow(key);
} catch (Exception e) {
return null;
}
}

}

0 comments on commit 065688b

Please sign in to comment.