| 
					
				 | 
			
			
				@@ -9,6 +9,9 @@ import android.content.pm.PackageInstaller; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.content.pm.PackageManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.net.Uri; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.os.Build; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.os.storage.StorageManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import android.os.storage.StorageVolume; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.emato.ich.utils.Log; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import androidx.annotation.NonNull; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -17,6 +20,7 @@ import androidx.annotation.RequiresApi; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.emato.ich.MainActivity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.emato.ich.utils.LoggingUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.emato.ich.utils.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.emato.ich.utils.ToastUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xuexiang.xupdate.entity.DownloadEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xuexiang.xupdate.listener.OnInstallListener; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -31,6 +35,9 @@ import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.InputStreamReader; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.OutputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.lang.reflect.Array; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.lang.reflect.InvocationTargetException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.lang.reflect.Method; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.text.DateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.text.SimpleDateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.Date; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -66,6 +73,64 @@ public class PackageManagerCompat implements OnInstallListener { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * android 9.0获取外置sdcard和U盘路径,并区分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param mContext  上下文 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     *  SD = "内部存储"; EXT = "SD卡"; USB = "U盘" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return apk 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static File getUpdateAPKFile(Context mContext){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String targetpath = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String keyword = "USB"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Class<?> storageVolumeClazz = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        File file = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            storageVolumeClazz = Class.forName("android.os.storage.StorageVolume"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Method getPath = storageVolumeClazz.getMethod("getPath"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Object result = getVolumeList.invoke(mStorageManager); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            final int length = Array.getLength(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Method getUserLabel = storageVolumeClazz.getMethod("getUserLabel"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (int i = 0; i < length; i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                StorageVolume storageVolumeElement = (StorageVolume) Array.get(result, i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String userLabel = (String) getUserLabel.invoke(storageVolumeElement); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String path = (String) getPath.invoke(storageVolumeElement); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(!userLabel.contains("内部存储") && !storageVolumeElement.isEmulated()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    targetpath = path; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    targetpath = targetpath +"/app-release.apk"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    file = new File(targetpath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (!file.exists()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        ToastUtils.make(mContext, "U盘根目录下不存在升级所需APK!请检查APK存放目录!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        return file; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (ClassNotFoundException e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Log.e(TAG, "类找不到异常", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LoggingUtils.sendAppErrorLog("类找不到异常", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (InvocationTargetException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Log.e(TAG, "反射调用目标方法异常", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LoggingUtils.sendAppErrorLog("反射调用目标方法异常", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (NoSuchMethodException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Log.e(TAG, "反射找不到目标方法", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LoggingUtils.sendAppErrorLog("反射找不到目标方法", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (IllegalAccessException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Log.e(TAG, "没有权限", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LoggingUtils.sendAppErrorLog("没有权限", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return file; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static void install(Context context, String apkFilePath, PackageManager packageManager, InstallListener listener) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 |