[TinyTut] - Android VibratorService

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Android version

Postby Bossly » Mon Dec 01, 2008 11:28 am

I can't find android.os.IVibratorService.Stub class like in tutorial so i use this part of code to implement vibration feature:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         Vibrator vb = ( Vibrator )getApplication().getSystemService( Service.VIBRATOR_SERVICE );
  3.  
  4.         vb.vibrate( new long[]{100,100,100,1000}, -1 );
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


There no exception and errors, but LogCat don't show any vibration action :?:
Using android-sdk-windows-2.1
Best wishes, Bossly
User avatar
Bossly
Freshman
Freshman
 
Posts: 8
Joined: Mon Dec 01, 2008 11:03 am

Top

Postby Darrell » Fri Dec 26, 2008 7:53 pm

I suspect that the changes made too the OS in the last year since this was originally posted mean the originally stated method no longer works. As for Bosslys method, It has no problems when written but produces a force close when run on the phone.

Anyone able to shed light on this?
Darrell
Freshman
Freshman
 
Posts: 9
Joined: Thu Nov 20, 2008 3:31 pm

Postby cyc380 » Tue Feb 24, 2009 11:46 pm

You need to include the VIBRATE uses permissions to the manifest.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. <uses-permission android:name="android.permission.VIBRATE"></uses-permission>
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
cyc380
Freshman
Freshman
 
Posts: 5
Joined: Sat Feb 07, 2009 5:40 am

problem with vibrate

Postby Sapientum » Wed Dec 02, 2009 11:38 am

hey guys, I'm trying to write some code that makes the phone vibrate and for testing purpose, I have made it so that when I press the volume up/down buttons it should vibrate, but the application is forced close, when I press a button.

My code is as following:

package example.Volume;

import android.app.Activity;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.content.Context;
import android.content.Intent;

public class Volume extends Activity {

private Vibrator vibrator;
int milliseconds = 500;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

}

@Override
//Creates a function that listen for whether a key is pressed
public boolean onKeyDown(int keyCode, KeyEvent ev) {//int _keyCode, KeyEvent _event)
switch(keyCode){
//Creates a case for each of the keys to listen to
case KeyEvent.KEYCODE_VOLUME_DOWN:
//Tells the application what to do when VOLUME_DOWN is pressed
vibrator.vibrate(milliseconds);
break;
case KeyEvent.KEYCODE_VOLUME_UP:
vibrator.vibrate(milliseconds);
break;
default:
return false;
}
return true;
}


}
Sapientum
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue Nov 24, 2009 3:56 pm

Postby zehunter » Wed Mar 17, 2010 3:55 pm

hi,

can any on can confirm that logcat output does not exist anymore with SDK 1.6? i use "vibrate" with getSystemService and nothing in log but no exception too ... i can see what i'm writing in log but nothing more ...
zehunter
Developer
Developer
 
Posts: 27
Joined: Sun Jan 10, 2010 10:45 am

Re: problem with vibrate

Postby allienz123 » Sun Feb 20, 2011 8:49 am

Sapientum wrote:hey guys, I'm trying to write some code that makes the phone vibrate and for testing purpose, I have made it so that when I press the volume up/down buttons it should vibrate, but the application is forced close, when I press a button.

My code is as following:

package example.Volume;

import android.app.Activity;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.content.Context;
import android.content.Intent;

public class Volume extends Activity {

private Vibrator vibrator;
int milliseconds = 500;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

}

@Override
//Creates a function that listen for whether a key is pressed
public boolean onKeyDown(int keyCode, KeyEvent ev) {//int _keyCode, KeyEvent _event)
switch(keyCode){
//Creates a case for each of the keys to listen to
case KeyEvent.KEYCODE_VOLUME_DOWN:
//Tells the application what to do when VOLUME_DOWN is pressed
vibrator.vibrate(milliseconds);
break;
case KeyEvent.KEYCODE_VOLUME_UP:
vibrator.vibrate(milliseconds);
break;
default:
return false;
}
return true;
}


}


Maybe you can check manifest permission for vibrate function
allienz123
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jan 12, 2011 1:59 pm

Top

Re: [TinyTut] - Android VibratorService

Postby invitrogenium » Sun Mar 20, 2011 5:27 pm

Hi there,

I have the same problem as described above: When my emulator vibrates nothing is shown in the log file.
Does anybody know if this is normal in newer (above 1.6) API versions?

Thanks a lot!
Cheers, Andreas
invitrogenium
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Mar 20, 2011 5:24 pm

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: Google [Bot] and 5 guests