override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
// React to activity result and if request code == ResultActivity.REQUEST_CODE
if (requestCode == UPDATE_REQUEST_CODE) {
//when user clicks update button
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(mContext, "App download starts...", Toast.LENGTH_LONG).show()
} else if (resultCode == Activity.RESULT_CANCELED) {
//if user click on close button
Toast.makeText(mContext, "App download canceled.", Toast.LENGTH_LONG).show()
//Here you can do whatever you want (call finish() to close the app.)
} else if (resultCode == ActivityResult.RESULT_IN_APP_UPDATE_FAILED) {
Toast.makeText(mContext, "App download failed.", Toast.LENGTH_LONG).show()
}
return true
}
return false
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_REQUEST_CODE) {
if (resultCode != RESULT_OK) {
log("Update flow failed! Result code: " + resultCode);
// If the update is cancelled or fails,
// you can request to start the update again.
}
}
}
3条答案
按热度按时间yeotifhr1#
请试试这个。
ppcbkaq52#
如果用户点击关闭按钮,您可以在此条件下获得回调resultCode == Activity.RESULT_CANCELED:-
mutmk8jj3#
我想你想不允许用户使用你的应用程序,直到他们更新应用程序?
为此,您可以监听更新状态,如果用户取消,您可以请求再次启动更新(可能会向用户显示一个对话框/消息,解释为什么需要更新)。
从文档中
获取更新状态回调
启动更新后,可以使用
onActivityResult()
回调来处理更新失败或取消,如下所示。