views:

180

answers:

3

So I am trying to simulate that the phone is receiving a call. I have successfully extracted the phones ring tone and played it. Now I want to simulate the vibration. While I can make the phone vibrate, I want to emulate the exact pattern that the phone vibrates with as when it receives a call. Is there some setting or class that I can use to extract this pattern, and also detect if vibration is turned on?

Cheers,

A: 

Why not use the Android source in order to see how they do it? :)

The Phone app source is available from http://android.git.kernel.org/?p=platform/packages/apps/Phone.git;a=tree

dparnas
+2  A: 

You have to vibrate it in a pattern.

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);  

// 1. Vibrate for 1000 milliseconds  
long milliseconds = 1000;  
v.vibrate(milliseconds);  

// 2. Vibrate in a Pattern with 500ms on, 500ms off for 5 times  
long[] pattern = { 500, 300 };  
v.vibrate(pattern, 5);

http://www.androidsnippets.org/snippets/22/

I'm not sure what pattern is used as standard, you could probably find it in the source, or else keep trying different patterns yourself until it is satisfactory.

Donal Rafferty
Your code works 100% perfect, thanks!
pcm2a
A: 

The second parameter to vibrate is not the number of times. Read the javadoc to get the correct usage.

Anon