shake

iOS: How to Implement a “Shake Device” event?

孤街醉人 提交于 2019-12-05 07:21:47
问题 I want to a "Shake Device" event to my app - i.e., when the user shakes the device something happens. I tried implementing: -(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.subtype == UIEventSubtypeMotionShake) { //something happens } } It doesn't seem to work....... Does anyone knows which method I should use? 回答1: Try using the below code, it worked fine for me. - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if ( event.subtype ==

Javascript. Listen for iPhone shake event?

余生颓废 提交于 2019-12-05 03:29:10
Is it possible to listen for an iPhone (or any mobile phone with accelerometer) shake event with JavaScript? You know like shaking the iPhone to shuffle the next song in iTunes I want to call a JS function on my website when the iPhone got shaken. Not as a straight web app, no. If you wrap your web app in PhoneGap , it exposes accelerometer and other app-only features to the site running within it, but the downside is that people have to actually download your app - they can't just browse to a site in Safari. In the latest iOS update (4.2) the accelorometer is now accessible from Javascript.

iPhone App increase Shake gesture Sensitivity

≡放荡痞女 提交于 2019-12-05 02:44:40
In my iPhone App I have used shake gesture it is working but it requires lots of efforts to shake Is there any way to make it more sensitive or increase the sensitivity? here is the code - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (motion == UIEventSubtypeMotionShake) { [self performSelector:@selector(startPressed:)]; } } Please help and Suggest. Thanks The isnt a way to do it directly as far as I'm aware. One way to get around this would be to use the accelerometer's readings, and then decide for yourself if it was a shake, you would be able to fine tune it

Objective C: Detecting a shake

若如初见. 提交于 2019-12-05 02:31:18
I'm using the shake api like this: - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.subtype == UIEventSubtypeMotionShake) { [img stopAnimating]; } } How do I detect that the shaking has stopped? You are on the right track, however, there are still more things you need to add to detect shaking: You can test this by adding an NSLog to the motionBegan or motionEnded methods, and in the Simulator, press CONTROL + COMMAND + Z #pragma mark - Shake Functions -(BOOL)canBecomeFirstResponder { return YES; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:NO];

unable to detect shake event when my phones screen is off in android

天涯浪子 提交于 2019-12-04 15:49:42
问题 In my application I want to detect the shake event and I'm using SensorEventListener, the code is working fine when my activity is running in foreground. But when I press the lock button of the phone to lock the screen, the shake event can't be detected. I have tested my code on the Samsung gts5360. But the same code is working fine on sony ericssion xperia mini pro. Actually my Samsung phone is not detecting the shake events when I leave the device idle for approx. 45 seconds, after locking

Android Shake(Sensor) Service For shake Detection in Application Background

心已入冬 提交于 2019-12-04 14:57:17
I have develop an Application that have shaking functionality for some function to work so i have use shaking class and implement to Main Activity so its work smoothly while Application running but my question is when my application going to sleep or kill or stop then how to detect shake in background (Service) My shacking class public class Shaker implements SensorListener { private static final int FORCE_THRESHOLD = 350; private static final int TIME_THRESHOLD = 200; private static final int SHAKE_TIMEOUT = 500; private static final int SHAKE_DURATION = 1000; private static final int SHAKE

Implementing a shake event

半世苍凉 提交于 2019-12-04 10:36:29
I'm having trouble figuring out how to implement the code from this answer. Android: I want to shake it Do I need to create a method and use an if statement to find if mAccel is greater than 0? package your.shake.namespace; import android.app.Activity; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.os.Vibrator; import android.widget.TextView; public class ShakeListener extends Activity { TextView display; Vibrator v;

How to shake on android 2.2

旧城冷巷雨未停 提交于 2019-12-04 05:21:16
问题 Does anybody know what is the shake code for android 2.2? I want on shake to make buzz on my application. Thanks. 回答1: Try this: /* put this into your activity class */ private SensorManager mSensorManager; private float mAccel; // acceleration apart from gravity private float mAccelCurrent; // current acceleration including gravity private float mAccelLast; // last acceleration including gravity private final SensorEventListener mSensorListener = new SensorEventListener() { public void

iOS: How to Implement a “Shake Device” event?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 21:32:31
I want to a "Shake Device" event to my app - i.e., when the user shakes the device something happens. I tried implementing: -(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.subtype == UIEventSubtypeMotionShake) { //something happens } } It doesn't seem to work....... Does anyone knows which method I should use? Try using the below code, it worked fine for me. - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if ( event.subtype == UIEventSubtypeMotionShake ) { //your code } if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )

Detecting shaking in html5 mobile

亡梦爱人 提交于 2019-12-03 15:52:39
I'm building a web app in html5 at the moment that needs to be able to detect when the user shakes their phone and how fast they are shaking it. I've been browsing around but can't seem to find any examples of how I could implement this. I know html5 has an accelerometer that can detect the orientation of the phone, but how does it detect the speed at which the user is shaking it? Also I'm testing this on my iPhone, although ideally I would like it to work on Android devices too. Thoughts? Examples would be great too. Thanks! You can use this jQuery plugin . And you can also read this... http: