-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat(appdistribution): add in-app-feedback support #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
197a062
ca654a8
e9cc93b
c142c9f
73141ba
2940487
9ea2ed6
8ba8dab
b22860c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
package com.google.firebase.appdistributionquickstart.java; | ||
|
||
import android.Manifest; | ||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.widget.Toast; | ||
|
||
import androidx.activity.result.ActivityResultLauncher; | ||
import androidx.activity.result.contract.ActivityResultContracts; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.core.content.ContextCompat; | ||
|
||
import com.google.firebase.appdistribution.FirebaseAppDistribution; | ||
import com.google.firebase.appdistribution.FirebaseAppDistributionException; | ||
import com.google.firebase.appdistribution.InterruptionLevel; | ||
import com.google.firebase.appdistributionquickstart.databinding.ActivityMainBinding; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = "AppDistribution-Quickstart"; | ||
|
||
// Declare the launcher at the top of your Activity/Fragment: | ||
private final ActivityResultLauncher<String> requestPermissionLauncher = | ||
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { | ||
if (!isGranted) { | ||
Toast.makeText( | ||
MainActivity.this, | ||
"The app won't display feedback notifications because the notification permission was denied", | ||
Toast.LENGTH_LONG | ||
).show(); | ||
} | ||
}); | ||
|
||
private FirebaseAppDistribution mFirebaseAppDistribution; | ||
|
||
@Override | ||
|
@@ -21,6 +41,19 @@ protected void onCreate(Bundle savedInstanceState) { | |
setContentView(binding.getRoot()); | ||
|
||
mFirebaseAppDistribution = FirebaseAppDistribution.getInstance(); | ||
|
||
binding.btShowNotification.setOnClickListener(view -> { | ||
mFirebaseAppDistribution.showFeedbackNotification( | ||
"Data Collection Notice", | ||
thatfiredev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
InterruptionLevel.HIGH | ||
); | ||
}); | ||
|
||
binding.btSendFeedback.setOnClickListener(view -> { | ||
mFirebaseAppDistribution.startFeedback("Thanks for sharing your feedback with us"); | ||
thatfiredev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
askNotificationPermission(); | ||
thatfiredev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
|
@@ -37,4 +70,29 @@ public void onResume() { | |
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
// Hide the notification once this activity is destroyed | ||
mFirebaseAppDistribution.cancelFeedbackNotification(); | ||
} | ||
Comment on lines
+75
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't need this anymore now that we made the change to automatically hide the notification There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When does the automatic hide take place? I tried closing the Activity, but it didn't dismiss the notification. Is it when the app is closed? |
||
|
||
private void askNotificationPermission() { | ||
// This is only necessary for API level >= 33 (TIRAMISU) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you want this check here anymore. Even if they are on an older device we still want to show the notification. On older devices the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc: @marinacoelho |
||
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. | ||
thatfiredev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
// Directly ask for the permission | ||
requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
package com.google.firebase.appdistributionquickstart.kotlin | ||
|
||
import android.Manifest | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.content.ContextCompat | ||
import com.google.firebase.appdistribution.FirebaseAppDistribution | ||
import com.google.firebase.appdistribution.FirebaseAppDistributionException | ||
import com.google.firebase.appdistribution.InterruptionLevel | ||
import com.google.firebase.appdistribution.ktx.appDistribution | ||
import com.google.firebase.appdistributionquickstart.databinding.ActivityMainBinding | ||
import com.google.firebase.ktx.Firebase | ||
|
@@ -12,12 +19,38 @@ class KotlinMainActivity : AppCompatActivity() { | |
|
||
private lateinit var firebaseAppDistribution: FirebaseAppDistribution | ||
|
||
// Declare the launcher at the top of your Activity/Fragment: | ||
private val requestPermissionLauncher = registerForActivityResult( | ||
ActivityResultContracts.RequestPermission() | ||
) { isGranted: Boolean -> | ||
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() | ||
// Hide the notification once this activity is destroyed | ||
firebaseAppDistribution.cancelFeedbackNotification() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Lee's comment above, I think we don't need this line here as well. |
||
} | ||
|
||
private fun askNotificationPermission() { | ||
// This is only necessary for API level >= 33 (TIRAMISU) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as Lee's comment above. And if we absolutely need to keep this check here, what do you think of changing this function a bit to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a |
||
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 { | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.