TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

Enable smartphone vibrate on Android on fcm retrieval #328

Open andyzukunft opened 3 months ago

andyzukunft commented 3 months ago

I noticed that the phone is not vibrating on fcm notification arrival (app is in background). The app should have the permission, the channel is configured to vibrate and I checked the app permission on the phone where "Sound and Vibration" is activated in Android. The current implementation only creates a notification sound and of course only if the phone is set to "loud" however a lot of phones nowadays are set to "silent / vibration" which results in the app not giving any indication that a notification is waiting.

Do you have an idea what to add/fix to enable vibrations for Android? Do we have to do anything for iOS?

AndroidManifest.xml

<uses-permission android:name="android.permission.VIBRATE" />

Android MainActivity.cs

Log.Debug($"Init FCM Channel");
var channelId = $"{PackageName}.general";

var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default);
channel.EnableVibration(true);
channel.EnableLights(true);
channel.LockscreenVisibility = NotificationVisibility.Public;

var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);

FirebaseCloudMessagingImplementation.ChannelId = channelId;
FirebaseCloudMessagingImplementation.SmallIconRef = Resource.Drawable.ic_notification_small;