17
17
import static android .view .View .GONE ;
18
18
import static android .view .View .VISIBLE ;
19
19
20
+ import android .app .Activity ;
21
+ import android .content .Intent ;
20
22
import android .graphics .Bitmap ;
21
23
import android .net .Uri ;
22
24
import android .os .Bundle ;
27
29
import android .widget .ImageView ;
28
30
import android .widget .TextView ;
29
31
import android .widget .Toast ;
32
+ import androidx .activity .result .ActivityResult ;
30
33
import androidx .activity .result .ActivityResultLauncher ;
31
- import androidx .activity .result .PickVisualMediaRequest ;
32
- import androidx .activity .result .contract .ActivityResultContracts .PickVisualMedia ;
34
+ import androidx .activity .result .contract .ActivityResultContracts .StartActivityForResult ;
33
35
import androidx .annotation .NonNull ;
34
36
import androidx .annotation .Nullable ;
35
37
import androidx .appcompat .app .AppCompatActivity ;
@@ -52,6 +54,9 @@ public class FeedbackActivity extends AppCompatActivity {
52
54
public static final String SCREENSHOT_URI_KEY =
53
55
"com.google.firebase.appdistribution.FeedbackActivity.SCREENSHOT_URI" ;
54
56
57
+ private final ActivityResultLauncher <Intent > chooseScreenshotLauncher =
58
+ registerForActivityResult (new StartActivityForResult (), this ::handleChooseScreenshotResult );
59
+
55
60
@ Inject FeedbackSender feedbackSender ;
56
61
@ Inject @ Blocking Executor blockingExecutor ;
57
62
@ Inject @ UiThread Executor uiThreadExecutor ;
@@ -81,6 +86,7 @@ protected void onCreate(Bundle savedInstanceState) {
81
86
screenshotUri = Uri .parse (getIntent ().getStringExtra (SCREENSHOT_URI_KEY ));
82
87
}
83
88
}
89
+
84
90
setupView ();
85
91
}
86
92
@@ -103,27 +109,14 @@ private void setupView() {
103
109
findViewById (R .id .backButton ).setOnClickListener (v -> finish ());
104
110
findViewById (R .id .sendButton ).setOnClickListener (this ::submitFeedback );
105
111
106
- // Registers a photo picker activity launcher in single-select mode
107
- ActivityResultLauncher <PickVisualMediaRequest > pickMedia =
108
- registerForActivityResult (
109
- new PickVisualMedia (),
110
- uri -> {
111
- if (uri != null ) {
112
- LogWrapper .d (TAG , "Selected custom screenshot URI: " + uri );
113
- screenshotUri = uri ;
114
- setupScreenshot ();
115
- } else {
116
- LogWrapper .d (TAG , "No custom screenshot selected. Not changing screenshot URI." );
117
- }
118
- });
119
-
120
112
findViewById (R .id .chooseScreenshotButton )
121
113
.setOnClickListener (
122
- v ->
123
- pickMedia .launch (
124
- new PickVisualMediaRequest .Builder ()
125
- .setMediaType (new PickVisualMedia .SingleMimeType ("image/png" ))
126
- .build ()));
114
+ v -> {
115
+ Intent intent = new Intent (Intent .ACTION_OPEN_DOCUMENT );
116
+ intent .addCategory (Intent .CATEGORY_OPENABLE );
117
+ intent .setType ("image/png" );
118
+ chooseScreenshotLauncher .launch (intent );
119
+ });
127
120
128
121
setupScreenshot ();
129
122
}
@@ -157,6 +150,19 @@ private void setupScreenshot() {
157
150
});
158
151
}
159
152
153
+ private void handleChooseScreenshotResult (ActivityResult activityResult ) {
154
+ int resultCode = activityResult .getResultCode ();
155
+ Intent intent = activityResult .getData ();
156
+ if (resultCode == Activity .RESULT_OK && intent != null && intent .getData () != null ) {
157
+ Uri uri = intent .getData ();
158
+ LogWrapper .d (TAG , "Selected custom screenshot URI: " + uri );
159
+ screenshotUri = uri ;
160
+ setupScreenshot ();
161
+ } else {
162
+ LogWrapper .d (TAG , "No custom screenshot selected. Not changing screenshot URI." );
163
+ }
164
+ }
165
+
160
166
@ Nullable
161
167
private Bitmap readScreenshot (@ Nullable Uri uri ) {
162
168
if (uri == null ) {
0 commit comments