activity判断

This commit is contained in:
Jerry Yan 2020-02-27 20:23:56 +08:00
parent c301cb1e62
commit 8f3de4f376

View File

@ -22,13 +22,11 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
private String downloadUrl;
private String title = "应用更新中";
private final Activity activity;
public UpgradeModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
this.activity = reactContext.getCurrentActivity();
}
@Override
@ -57,6 +55,7 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
}
private void _requestInstallPermission() {
Activity activity = reactContext.getCurrentActivity();
if (activity == null) return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Uri packageURI = Uri.parse("package:" + activity.getPackageName());
@ -67,6 +66,7 @@ public class UpgradeModule extends ReactContextBaseJavaModule {
@ReactMethod
public void startDownload() {
Activity activity = reactContext.getCurrentActivity();
if (activity == null) return;
if (!this._hasPermissionToInstall()) this._requestInstallPermission();
DownloadManager downloadManager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);