c# - call method when phone is shaken -


this question has answer here:

i have created windows phone app locates users location when button pressed want away button , make function occur when phone shaken! below code have created far, when application loads call function called locate_me initializes accelerometer.

private async void locate_me()     {          if (accelerometer == null)         {             // instantiate accelerometer.             accelerometer = new accelerometer();             accelerometer.timebetweenupdates = timespan.frommilliseconds(20);             accelerometer.currentvaluechanged +=                 new eventhandler<sensorreadingeventargs<accelerometerreading>>(accelerometer_currentvaluechanged);         }          try         {             statustextblock.text = "starting accelerometer.";             accelerometer.start();         }         catch (invalidoperationexception ex)         {             statustextblock.text = "unable start accelerometer.";         }  } 

so how go making onshaken function?

first step: download shakegestures library microsoft site here. add shakegetures.dll project. it's piece of cake detect shake gestures. below code can use:

 //constructor of page register event handler shake  public page1()     {         initializecomponent();             // register shake event         shakegestureshelper.instance.shakegesture +=new             eventhandler<shakegestureeventargs>(instance_shakegesture);              // optional, set parameters             shakegestureshelper.instance.minimumrequiredmovesforshake = 2;              // start shake detection             shakegestureshelper.instance.active = true;     }     private void instance_shakegesture(object sender, shakegestureeventargs e)     {       //call method     } 

this minimal code require. worked me.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -