Last active
May 18, 2020 07:28
-
-
Save EdgeJH/80e2e2811651633b5f171a90dc0ab2be to your computer and use it in GitHub Desktop.
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
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_immediate_update); | |
UpdateManager.Builder builder = new UpdateManager.Builder() | |
.setActivity(this) | |
.setUpdateType(UpdateType.FLEXIBLE); | |
final UpdateManager updateManager = builder.create(); | |
updateManager.setUpdateListener(new UpdateListener() { | |
@Override | |
public void onUpdateChecked(@NotNull AppUpdateInfo appUpdateInfo, boolean updateAvailable) { | |
if (updateAvailable){ | |
updateManager.update(appUpdateInfo); | |
} | |
} | |
@Override | |
public void onUpdateCheckFailure(@Nullable Exception exception) { | |
if (exception!=null){ | |
Toast.makeText(FlexibleUpdateActivity.this, "error : " + exception.getMessage(), Toast.LENGTH_SHORT).show(); | |
} | |
} | |
@Override | |
public void onUpdateState(@NotNull InstallState installState, long bytesDownLoaded, long totalBytesToDownLoaded) { | |
if (installState.installStatus()== InstallStatus.DOWNLOADED){ | |
//업데이트 완료 | |
} | |
} | |
}); | |
updateManager.checkUpdate(); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == UpdateManager.UPDATE_REQ_CODE) { | |
switch (resultCode) { | |
case RESULT_OK: | |
//업데이트 완료 | |
break; | |
case RESULT_CANCELED: | |
//업데이트 취소 | |
break; | |
default: | |
//업데이트 실패 | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment