Mobile phone shake

Source: Internet
Author: User

 

You can use the mobile phone's vibration function to send a specific style of vibration to the mobile phone for notification. Android allows you to control the vibration style. You can use the vibration to convey information to get users' attention.

 

To set the vibration style, set a time array for the vibrate attribute of notification. Construct an array. The numbers at each interval correspond to the duration of the vibration or pause (in millimeters ).

 

Before using vibration in your program, you need to grant permissions to the program. Use the following code snippet to add a uses-Permission node to the application:

 

<Uses-Permission Android: Name = "android. Permission. Vibrate"/>

 

The following example shows how to modify the vibration of notification. In the repeated mode, the system vibrates for one second and stops for one second, for a total of five seconds.

 

Long [] vibrate = new long [] {1000,100 0, 1000,100 0, 1000 };

Notification. vibrate = vibrate;

 

You can use this subtle control to transmit information to users. Next, we will update the announcenewquake method and set the vibration style of the mobile phone based on the earthquake level. Earthquakes are measured exponentially. Therefore, you can use the same measurement method to create a vibration style.

 

For a very small magnitude 1 earthquake that can be felt, the mobile phone will shake a little bit of time; but for a magnitude 10 earthquake, it can tear the earth into two halves, and then the mobile phone will shake for 20 seconds. For most earthquakes between 3 and 7, mobile phones will shake between 200mm and 4 seconds.

 

Double vibratelength = 100 * Math. exp (0.53 * quake. getmagnitude ());

Long [] vibrate = new long [] {100,100, (long) vibratelength };

Newearquakenotification. vibrate = vibrate;

 

The current Android simulator cannot intuitively or hear the vibration of the device. To verify that notification works properly, you can monitor the log output of "vibration on"/"vibration off.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.