Windows8 gravity acceleration sensing

Source: Internet
Author: User
The accelerometer demonstrates the use of windows. devices. sensors. The API of the accelerometer. This simple allows users to browse the accelerated army along X-, Y-, and a 3-axis Z-axes accelerometer. You can choose one of the three scenarios: • Events of accelerometer data • Events of accelerometer shake • Read acclerometer Data Events of the existing accelerometer when you choose to enable choice of Button accelerometer data items, apply Program Starts the Flow Acceleration Sensor reading in real time. Accelerometer shake event when you choose to make the button accelerometer shake event option, this application shows the cumulative number of Vibrations for each event to occur. (This application first increases the event count and then makes the most recent value .) Existing accelerometer read when you choose to make the button for the current accelerometer read option, this application will resume reading of the latest accelerometer.

 

 ClassSuspensionmanager

{
Static Private Dictionary < String , Object > Sessionstate _ = New Dictionary < String , Object > ();
Static Private List <type> knowntypes _ = New List <type> ();
Private Const String Filename = " _ Sessionstate. xml " ;

//Provides access to the currect session state
Static PublicDictionary <String,Object> Sessionstate
{
Get{ReturnSessionstate _;}
}

//Allows custom types to be added to the list of types that can be serialized
Static PublicList <type> knowntypes
{
Get{ReturnKnowntypes _;}
}

// Save the current session state
Static Async Public Task saveasync ()
{
// Get the output stream for the sessionstate file.
Storagefile file = await applicationdata. Current. localfolder. createfileasync (filename, creationcollisionoption. replaceexisting );
Irandomaccessstream rastream = await file. openasync (fileaccessmode. readwrite );
Using (Ioutputstream outstream = rastream. getoutputstreamat ( 0 ))
{
// Serialize the session state.
Datacontractserializer serializer = New Datacontractserializer ( Typeof (Dictionary <String , Object >), Knowntypes _);
Serializer. writeobject (outstream. asstreamforwrite (), sessionstate _);
Await outstream. flushasync ();
}
}

// Restore the saved sesison state
Static Async Public Task restoreasync ()
{
// Get the input stream for the sessionstate file.
Try
{
Storagefile file = await applicationdata. Current. localfolder. getfileasync (filename );
If (File = Null ) Return ;
Iinputstream instream = await file. opensequentialreadasync ();

// Deserialize the session state.
Datacontractserializer serializer = New Datacontractserializer ( Typeof (Dictionary < String , Object >), Knowntypes _);
Sessionstate _ = (Dictionary < String , Object >) Serializer. readobject (instream. asstreamforread ());
}
Catch (Exception)
{
// Restoring State is best-effort. If it fails, the app will just come up with a new session.
}
}
}

Complete demo

/Files/risk/windows8/gravity acceleration sensor sample.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.