Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 2    Views: 1860

Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
03/24/12 03:37 PM (13 years ago)

Android Apps - how to make buttons vibrate

This makes buttons in your app vibrate, replicating the vibration on the android phone buttons. I'm using two single quotes in place of double quotes, so if you copy and paste, replace them! Add to manifest: <uses-permission android:name=''android.permission.VIBRATE'' /> I'm going to make the buttons in a button menu list vibrate. You can put vibrate where you like, like for a wrong quiz question. BT_screen_menuButtons.java: Add an import: import android.os.Vibrator; ------------------------------------- Add a class: Vibrator vibr; ------------------------------------- Add to public void onCreate after the LinearLayout baseView: vibr = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); ------------------------------------- Add to button onClick: vibr.vibrate(28); ------------------------------------- That's it! Setting to 28 roughly replicates a phones button vibration. You can put any number in here to change the length. Screenshots: http://imageshack.us/f/62/screenshotsfn.jpg/
 
AppGuy30
Code is Art
Profile
Posts: 737
Reg: Oct 29, 2011
location unknow...
14,070
like
03/24/12 07:53 PM (13 years ago)
very cool thing to know
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
09/19/13 01:37 PM (12 years ago)
Hey raveyd! Not sure if you're still hanging out here. But i've tried to add this to the latest android 3.0 app and I get errors. I hope you are well thanks for any info
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.