6

Vibrations in .NET MAUI

 1 year ago
source link: https://askxammy.com/vibrations-in-net-maui-%f0%9f%92%9a/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

.Net MAUI

Vibrations in .NET MAUI

Leomaris Reyes / 30 September, 2022
VibrationsAskXammy.png

We must take advantage and use the functionalities of our devices, through vibration we have access to inform actions / processes to our users through a physical reaction. Today we will learn in a very simple and quick way how to send vibrations from .NET MAUI!


🔧  First of all… What do I need?

Let’s start by adding some platform settings. To implement them, follow the instructions added below:

La imagen tiene un atributo ALT vacío; su nombre de archivo es if_android_313085.png

We have two ways to do it, let’s see:

1⃣ Go to  Platform ➖Android ➖ AndroidManifes.cs and add the following Permission:

2⃣  Or just go to your AssemblyInfo.cs and add the following:

🚧  For iOS/macOS and Windows you don’t need an additional configuration.


Let’s start!

The Vibration can be requested for a certain time or the default value of 500 milliseconds, let’s see how to do it:

📲  Sending Vibration

Through the .Default property we can access the Vibration method which allows us to send vibrations to our device, it accepts a TimeSpan as a parameter that represents a time interval.

❌ Canceling Vibration

But also, we have the Cancel method that allows us to stop the vibration emitted.


Platform differences

if_apple-ios-system-platform-os-mac-linux_652586.png

  • Only vibrates for 500 milliseconds.
  • Once started, vibration cannot be cancelled.
  • It only vibrates when the device is set to “Vibrate when ringing”.

🚧  For Android and Windows you don’t have platform diferences.


Spanish post: 

References: https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device/vibrate?tabs=android?WT.mc_id=DT-MVP-50033

Tagged .NetMaui, AskXammy


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK