[英]Is there an event when user cancels intent chooser?
In my android application I want the user to choose, which other application should be used to display a certain image if there are more than one possible apps. 在我的Android应用程序中,我希望用户选择,如果存在多个可能的应用程序,则应使用哪个其他应用程序来显示特定图像。 Therefore I got following code:
因此我得到以下代码:
final Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uri, IMAGE_MIME_TYPE)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent);
As intented an app chooser is displayed. 按预期显示应用选择器。
Right before I call startActivity
I open a ProgressDialog
, which I want to close when for example the user cancels the app chooser via back button. 在调用
startActivity
之前,我打开一个ProgressDialog
,例如,当用户通过后退按钮取消应用选择器时,我想关闭该对话框。 What is the best way to identify that the app chooser was canceled? 识别应用选择器已取消的最佳方法是什么? In other words - where should I close my
ProgressDialog
? 换句话说-我应该在哪里关闭
ProgressDialog
?
Start an activity like this: 开始这样的活动:
context.startActivityForResult(viewIntent, <int flag>);
Then in onActivityResult()
: 然后在
onActivityResult()
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == <int flag>) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user pressed ok
}else{
// The user pressed cancel
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.