I did some other work in the past two days because I used the arraylist class when I used the getproviders () method yesterday. I suddenly wanted to have a deep understanding of its mechanism, and I got a lot of results, I had a very tangled look at the Java Collection framework analyzed by a great god.Source codeIn this way, the Fail fast mechanism is naked and the coreCodeTake me into the design mode of the door, the original source code uses the decorator design mode, today I also summarized the learning results in http://blog.csdn.net/octobershiner/article/details/6631997
To put it bluntly, to call the Android system, only one class is vibrator. In the hard package, you need to set the permissions through the manifest. xml file to view system-level services.
1 <? XML version = "1.0" encoding = "UTF-8" ?>
2 < Manifest Xmlns: Android = "Http://schemas.android.com/apk/res/android"
3 Package = "Uni. vibrator"
4 Android: versioncode = "1"
5 Android: versionname = "1.0" >
6 < Uses-SDK Android: minsdkversion = "8" />
7
8 < Application Android: icon = "@ Drawable/icon" Android: Label = "@ String/app_name" >
9 < Activity Android: Name = ". Vibratordemoactivity"
10 Android: Label = "@ String/app_name" >
11 < Intent-Filter >
12 < Action Android: Name = "Android. Intent. Action. Main" />
13 < Category Android: Name = "Android. Intent. Category. launcher" />
14 </ Intent-Filter >
15 </ Activity >
16
17 </ Application >
18 < Uses-Permission Android: Name = "Android. Permission. Vibrate" />
19 </ Manifest >
Let's take a look at the SDK.
Class that operates the vibrator on the device.
If your process exits, any vibration you started with will stop.
// The Vibrator class is used to operate the vibration on the device. If your thread exits, the starting vibration will also stop.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------
Public void vibrate (long [] pattern, int repeat)
Since: API Level 1
Vibrate with a given pattern. // vibrate according to the given rhythm
Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. the first value indicates the number of milliseconds to wait before turning the vibrator on. the next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
// Pass an integer array as the duration for disabling and enabling the vibration, in milliseconds. The first value indicates the number of milliseconds to wait for the vibration to start. The next value indicates the number of milliseconds to keep the vibration.
To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or-1 to disable repeating.
// In order to repeatedly vibrate at the set rhythm, the index parameter is passed to indicate the number of repetitions, and the-1 parameter is used to indicate non-repetition.
Parameters
Pattern an array of longs of times for which to turn the vibrator on or off.
Repeat the index into pattern at which to repeat, or-1 if you don't want to repeat.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------
It also contains a method called Cancel to cancel the vibration.
DEMO code
1 /*
2 * @ Author octobershiner
3 * 2011 7 25
4 * Se. Hit
5 * A demo that uses Android mobile phones to vibrate
6 * */
7 Package Uni. vibrator;
8
9 Import Android. App. activity;
10 Import Android. content. context;
11 Import Android. OS. Bundle;
12 Import Android. OS. vibrator;
13
14 Public Class Vibratordemoactivity Extends Activity {
15 Private Vibrator vibrator;
16 /** Called when the activity is first created. */
17 @ Override
18 Public Void Oncreate (bundle savedinstancestate ){
19 Super . Oncreate (savedinstancestate );
20 Setcontentview (R. layout. Main );
21
22 /*
23 * If you want to set the vibration size, you can change the pattern. If the enabling time is too short, the vibration effect may not be felt.
24 * */
25 Vibrator = (vibrator) getsystemservice (context. vibrator_service );
26 Long [] Pattern = {100,400,100,400 }; // Stop enabling stop enabling
27 Vibrator. vibrate (pattern, 2 );// Repeat the pattern twice. If you only want to shake the pattern once, set the index to-1.
28 }
29
30 Public Void Onstop (){
31 Super . Onstop ();
32 Vibrator. Cancel ();
33 }
34 }
I don't know how to simulate it on a virtual machine, so I have to test it on a real machine first. If I know how to simulate it on a simulator, I 'd like to tell you about it ~