From 197a0622c67848515cb12b37d689088169d307e7 Mon Sep 17 00:00:00 2001 From: rosariopf Date: Mon, 13 Feb 2023 16:10:59 +0000 Subject: [PATCH 1/9] chore(fad): add snapshot dependency --- appdistribution/app/build.gradle | 3 ++- appdistribution/build.gradle | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/appdistribution/app/build.gradle b/appdistribution/app/build.gradle index 9825af2c2..524d62473 100644 --- a/appdistribution/app/build.gradle +++ b/appdistribution/app/build.gradle @@ -50,7 +50,8 @@ dependencies { implementation platform('com.google.firebase:firebase-bom:31.2.0') // ADD the SDK to the "prerelease" variant only (example) - implementation 'com.google.firebase:firebase-appdistribution-ktx:16.0.0-beta01' + // TODO(thatfiredev): Replace with public version once it's released + implementation 'com.google.firebase:firebase-appdistribution-api-ktx:16.0.1-SNAPSHOT' // For an optimal experience using App Distribution, add the Firebase SDK // for Google Analytics. This is recommended, but not required. diff --git a/appdistribution/build.gradle b/appdistribution/build.gradle index d0c3756dc..a054ded85 100644 --- a/appdistribution/build.gradle +++ b/appdistribution/build.gradle @@ -19,6 +19,13 @@ allprojects { mavenLocal() google() mavenCentral() + + // TODO(EAP Tester): + // 1. Download the zip file according to the provided instructions + // 2. Replace the $root variable with the absolute path to your quickstart app + def root = "Users/rosariopf/AndroidStudioProjects/quickstart-android/appdistribution" + maven { url "file://$root/firebase-app-distribution-eap-repo" } + // TODO(thatfiredev): remove this repo once the feature is publicly available } } From ca654a8d08950f37dbb6748bf0e0e7306de223ad Mon Sep 17 00:00:00 2001 From: rosariopf Date: Mon, 13 Feb 2023 16:11:22 +0000 Subject: [PATCH 2/9] feat(fad): add in app feedback buttons --- .../app/src/main/AndroidManifest.xml | 2 + .../kotlin/KotlinMainActivity.kt | 56 +++++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 24 +++++++- .../app/src/main/res/values/strings.xml | 2 + 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/appdistribution/app/src/main/AndroidManifest.xml b/appdistribution/app/src/main/AndroidManifest.xml index a29b19adf..a856cdcdf 100644 --- a/appdistribution/app/src/main/AndroidManifest.xml +++ b/appdistribution/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ + + + if (!isGranted) { + Toast.makeText( + this@KotlinMainActivity, + "The app won't display feedback notifications because the notification permission was denied", + Toast.LENGTH_LONG + ).show() + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) firebaseAppDistribution = Firebase.appDistribution + + binding.btShowNotification.setOnClickListener { + firebaseAppDistribution.showFeedbackNotification( + "Data Collection Notice", + InterruptionLevel.HIGH + ) + } + + binding.btSendFeedback.setOnClickListener { + firebaseAppDistribution.startFeedback("Thanks for sharing your feedback with us") + } + + askNotificationPermission() } override fun onResume() { @@ -34,7 +67,30 @@ class KotlinMainActivity : AppCompatActivity() { } } + override fun onDestroy() { + super.onDestroy() + // FYI: This is no longer needed in the most recent versions of EAP + firebaseAppDistribution.cancelFeedbackNotification() + } + private fun askNotificationPermission() { + // This is only necessary for API level >= 33 (TIRAMISU) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) == + PackageManager.PERMISSION_GRANTED + ) { + // All set. We can post notifications + } else if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) { + // Display an educational UI explaining to the user the features that will be enabled + // by them granting the POST_NOTIFICATION permission. This UI should provide the user + // "OK" and "No thanks" buttons. If the user selects "OK," directly request the permission. + // If the user selects "No thanks," allow the user to continue without notifications. + } else { + // Directly ask for the permission + requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) + } + } + } companion object { diff --git a/appdistribution/app/src/main/res/layout/activity_main.xml b/appdistribution/app/src/main/res/layout/activity_main.xml index 8debdf326..2ae51a660 100644 --- a/appdistribution/app/src/main/res/layout/activity_main.xml +++ b/appdistribution/app/src/main/res/layout/activity_main.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" - tools:context=".MainActivity"> + tools:context=".kotlin.KotlinMainActivity"> +