mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	Fix install apk under android 7
This commit is contained in:
		| @@ -2,6 +2,8 @@ | |||||||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|     package="cn.reactnative.modules.update"> |     package="cn.reactnative.modules.update"> | ||||||
|     <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> |     <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> | ||||||
|  |  | ||||||
|  |     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||||||
|     <application> |     <application> | ||||||
|         <meta-data android:name="pushy_build_time" android:value="@string/pushy_build_time" /> |         <meta-data android:name="pushy_build_time" android:value="@string/pushy_build_time" /> | ||||||
|         <provider |         <provider | ||||||
|   | |||||||
| @@ -4,7 +4,10 @@ import android.content.Context; | |||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
| import android.content.pm.PackageInfo; | import android.content.pm.PackageInfo; | ||||||
| import android.content.pm.PackageManager; | import android.content.pm.PackageManager; | ||||||
|  | import android.os.Build; | ||||||
|  | import android.os.Environment; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
|  |  | ||||||
| import com.facebook.react.ReactInstanceManager; | import com.facebook.react.ReactInstanceManager; | ||||||
|  |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| @@ -13,7 +16,6 @@ import java.util.concurrent.Executor; | |||||||
| import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||||
|  |  | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.net.URL; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by tdzl2003 on 3/31/16. |  * Created by tdzl2003 on 3/31/16. | ||||||
| @@ -107,7 +109,14 @@ public class UpdateContext { | |||||||
|         params.url = url; |         params.url = url; | ||||||
|         params.hash = hash; |         params.hash = hash; | ||||||
|         params.listener = listener; |         params.listener = listener; | ||||||
|         params.targetFile = new File(rootDir, fileName); |  | ||||||
|  |         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N && fileName.equals("update.apk")) { | ||||||
|  |             params.targetFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "pushy_update.apk"); | ||||||
|  |  | ||||||
|  |         } else { | ||||||
|  |             params.targetFile = new File(rootDir, fileName); | ||||||
|  |  | ||||||
|  |         } | ||||||
| //        params.unzipDirectory = new File(rootDir, hash); | //        params.unzipDirectory = new File(rootDir, hash); | ||||||
|         new DownloadTask(context).executeOnExecutor(this.executor, params); |         new DownloadTask(context).executeOnExecutor(this.executor, params); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -125,14 +125,13 @@ public class UpdateModule extends ReactContextBaseJavaModule { | |||||||
|             intent.setData(apkUri); |             intent.setData(apkUri); | ||||||
|             intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |             intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | ||||||
|             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||||
|             mContext.startActivity(intent); |  | ||||||
|         } else { |         } else { | ||||||
|             apkUri = Uri.fromFile(toInstall); |             apkUri = Uri.fromFile(toInstall); | ||||||
|             intent = new Intent(Intent.ACTION_VIEW); |             intent = new Intent(Intent.ACTION_VIEW); | ||||||
|             intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); |             intent.setDataAndType(apkUri, "application/vnd.android.package-archive"); | ||||||
|             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||||||
|             mContext.startActivity(intent); |  | ||||||
|         } |         } | ||||||
|  |         mContext.startActivity(intent); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ReactMethod |     @ReactMethod | ||||||
|   | |||||||
							
								
								
									
										19
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								lib/index.js
									
									
									
									
									
								
							| @@ -3,7 +3,12 @@ import { | |||||||
|   getCheckUrl, |   getCheckUrl, | ||||||
|   setCustomEndpoints, |   setCustomEndpoints, | ||||||
| } from './endpoint'; | } from './endpoint'; | ||||||
| import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; | import { | ||||||
|  |   NativeEventEmitter, | ||||||
|  |   NativeModules, | ||||||
|  |   Platform, | ||||||
|  |   PermissionsAndroid, | ||||||
|  | } from 'react-native'; | ||||||
| export { setCustomEndpoints }; | export { setCustomEndpoints }; | ||||||
| const { | const { | ||||||
|   version: v, |   version: v, | ||||||
| @@ -197,6 +202,18 @@ export function markSuccess() { | |||||||
|  |  | ||||||
| export async function downloadAndInstallApk({ url, onDownloadProgress }) { | export async function downloadAndInstallApk({ url, onDownloadProgress }) { | ||||||
|   logger('downloadAndInstallApk'); |   logger('downloadAndInstallApk'); | ||||||
|  |   if (Platform.OS === 'android' && Platform.Version <= 23) { | ||||||
|  |     try { | ||||||
|  |       const granted = await PermissionsAndroid.request( | ||||||
|  |         PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, | ||||||
|  |       ); | ||||||
|  |       if (granted !== PermissionsAndroid.RESULTS.GRANTED) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |     } catch (err) { | ||||||
|  |       console.warn(err); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|   let hash = Date.now().toString(); |   let hash = Date.now().toString(); | ||||||
|   let progressHandler; |   let progressHandler; | ||||||
|   if (onDownloadProgress) { |   if (onDownloadProgress) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm