简体   繁体   English

用户取消意图选择器时会发生事件吗?

[英]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.

相关问题 在使用意图选择器时,如何知道用户选择了哪个应用程序? - How to know which application the user chose when using an intent chooser? 检测用户何时取消打字 - Detect when a user cancels typing 使用Intent Chooser时视频会自动恢复 - Video automatically resumed when using Intent Chooser 检测选择器意图中何时没有合适的活动 - Detect when there is no suitable activity in chooser intent 用户取消SENDTO选择器后,getSupportFragmentManager()使应用程序崩溃(但如果打开了电子邮件应用程序,则不会崩溃) - getSupportFragmentManager() crashes app after user cancels a SENDTO chooser (but not if e-mail app is opened) 用户在Android中取消通知时是否可以收听? - Is it possible to listen for when a user cancels a Notification in Android? Android如何根据选择器意图中的用户操作请求权限 - Android how to request permission based on user action in chooser intent 在用户可以输入文本之前出现android Intent选择器 - android intent chooser appears before user can input text 如何确定用户使用默认的startActivity(intent)选择器选择的应用程序? - How to determine which app the user selects with the default startActivity(intent) chooser? 知道用户是否从选择器中选择了意图动作的方法 - way to know if the user has chosen the intent action from chooser or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM