Skip to content

Commit 41eb94e

Browse files
committed
Use plain Activity Results API to avoid having to raise compile/target SDK version
1 parent b26c892 commit 41eb94e

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

firebase-appdistribution/firebase-appdistribution.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ firebaseLibrary {
2222
}
2323

2424
android {
25-
compileSdk 31
25+
compileSdkVersion project.targetSdkVersion
2626

2727
defaultConfig {
2828
minSdkVersion 16
29-
targetSdkVersion 31
29+
targetSdkVersion project.targetSdkVersion
3030
multiDexEnabled true
3131
versionName version
3232
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -71,7 +71,6 @@ dependencies {
7171

7272
compileOnly 'com.google.auto.value:auto-value-annotations:1.6.5'
7373
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
74-
implementation 'androidx.activity:activity:1.6.1'
7574
implementation 'androidx.appcompat:appcompat:1.3.1'
7675
implementation "androidx.browser:browser:1.3.0"
7776
implementation "androidx.constraintlayout:constraintlayout:2.1.4"

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FeedbackActivity.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import static android.view.View.GONE;
1818
import static android.view.View.VISIBLE;
1919

20+
import android.app.Activity;
21+
import android.content.Intent;
2022
import android.graphics.Bitmap;
2123
import android.net.Uri;
2224
import android.os.Bundle;
@@ -27,9 +29,9 @@
2729
import android.widget.ImageView;
2830
import android.widget.TextView;
2931
import android.widget.Toast;
32+
import androidx.activity.result.ActivityResult;
3033
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;
3335
import androidx.annotation.NonNull;
3436
import androidx.annotation.Nullable;
3537
import androidx.appcompat.app.AppCompatActivity;
@@ -52,6 +54,9 @@ public class FeedbackActivity extends AppCompatActivity {
5254
public static final String SCREENSHOT_URI_KEY =
5355
"com.google.firebase.appdistribution.FeedbackActivity.SCREENSHOT_URI";
5456

57+
private final ActivityResultLauncher<Intent> chooseScreenshotLauncher =
58+
registerForActivityResult(new StartActivityForResult(), this::handleChooseScreenshotResult);
59+
5560
@Inject FeedbackSender feedbackSender;
5661
@Inject @Blocking Executor blockingExecutor;
5762
@Inject @UiThread Executor uiThreadExecutor;
@@ -81,6 +86,7 @@ protected void onCreate(Bundle savedInstanceState) {
8186
screenshotUri = Uri.parse(getIntent().getStringExtra(SCREENSHOT_URI_KEY));
8287
}
8388
}
89+
8490
setupView();
8591
}
8692

@@ -103,27 +109,14 @@ private void setupView() {
103109
findViewById(R.id.backButton).setOnClickListener(v -> finish());
104110
findViewById(R.id.sendButton).setOnClickListener(this::submitFeedback);
105111

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-
120112
findViewById(R.id.chooseScreenshotButton)
121113
.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+
});
127120

128121
setupScreenshot();
129122
}
@@ -157,6 +150,19 @@ private void setupScreenshot() {
157150
});
158151
}
159152

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+
160166
@Nullable
161167
private Bitmap readScreenshot(@Nullable Uri uri) {
162168
if (uri == null) {

0 commit comments

Comments
 (0)