Learn Windows Phone7 development together (15. Device)

Source: Internet
Author: User

Accelerometer

The accelerometer API is used to obtain data from the gravitational acceleration sensor, which is used to develop programs such as games.

if (am != null)
    am.Stop();
am = new Accelerometer();
am.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(am_ReadingChanged);// 监控重力加速数据。
try//因为启动时,如果出错会抛出异常,所以要用try块来处理。
{
     am.Start();//开始获取数据
}
catch(AccelerometerFailedException e)
{
}
  am.Stop();//停止获取数据。
void am_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
      //获取数。
}

Location Service

Positioning API, providing GPS, WIFI, lbs and other ways to obtain location data. And you can use one or more square ways to get the location data at the same time.

Watcher = new GeoCoordinateWatcher (Geopositionaccuracy.default);
Watcher. Movementthreshold = 35;//the distance (in meters) that must be moved relative to the coordinates in the last PositionChanged event, and the location provider will raise another positionchanged event after the distance is moved.
Watcher. PositionChanged + = new Eventhandler<geopositionchangedeventargs<geocoordinate>> (watcher_ positionchanged);//monitor location data changes
Watcher. StatusChanged + = new eventhandler<geopositionstatuschangedeventargs> (watcher_statuschanged);//Monitor Service status change

Watcher. Start ();//starts the location service to get the data. However, the service may not be available at this time, or waiting for too long to start, you can call the Start method with timeout, if the timeout, stop the boot.
Watcher. Trystart (True, Timespan.frommilliseconds (5000));
if (watcher. Status = = Geopositionstatus.ready)
This. Pagetitle.text = "service start";
Else
This. Pagetitle.text = "Service Not start";
Watcher. Stop ();//discontinue service.

void Watcher_positionchanged (object sender, Geopositionchangedeventargs<geocoordinate> e)
{
The location data that can be obtained
E.position.location.altitude.tostring ("0.000")
E.position.location.latitude.tostring ("0.000")
E.position.location.longitude.tostring ("0.000")
E.position.location.speed.tostring ("0.000");
}
void Watcher_statuschanged (object sender, Geopositionstatuschangedeventargs e)
{
E.status.tostring ()//Get Service status
}

Because it is in the simulator, the above two interfaces are actually not available, but if you want to develop the program process, must use these data and how to do? In fact, WP7 also provides another way to virtual these devices to receive analog data. This way you can use this method to test your own game while developing the game.

FM Radio

The radio API is provided in the WP7, and it can be seen that there are radios in the real machine in the future. The API for this radio is singleton mode, which means that an application can have only one radio instance. But there are only three areas to be heard: Europe, Japan, United States.

FMRadio radio = FMRadio.Instance;
radio.CurrentRegion = RadioRegion.Europe;
radio.Frequency = 100.5;
radio.PowerMode = RadioPowerMode.On;

Vibrate Controller

The vibration controller is used to start and stop the vibrator on the WP7.

VibrateController vc = VibrateController.Default;
vc.Start(TimeSpan.FromMilliseconds(100));
vc.Stop();

WP7 has provided the device interface seems to be quite a lot, but has not found Bluetooth, WiFi and other interfaces, do not know whether the WP7 on the device, or do not provide these interfaces? Or is it because the beta version of the SDK is not added?

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.