×
Namespaces

Variants
Actions
Revision as of 14:14, 30 October 2009 by croozeus (Talk | contribs)

Archived:Accessing system resources with PySymbian on S60 3rd Edition devices

From Nokia Developer Wiki
Jump to: navigation, search

Contents

Introduction

A common problem in developing applications in Flash Lite or WRT is the poor access to S60 resources. These languages don't have access to GPS, Bluetooh, Contacts, SMS, etc in the S60 3rd Edition.

In this post we'll show a Flash Lite application which can access S60 3rd Edition internal resources using PyS60.

Solution

This was done using the architecture and implementation showed in the following post.

Like was showed in the post, a client application has access to S60 internal resources throught HTTP requests. In ActionScript 2.0 (which is used in Flash Lite 2.x and 3.x) a HTTP request can be executed using the LoadVars class. The basic use of this class is showed below:

var lv:LoadVars = new LoadVars();
lv.onLoad = function(success:Boolean){
//Actions when data is loaded.
}
lv.sendAndLoad("http://example.com",lv,"GET");

The parameters of sendAndLoad method are:

  • "http://example.com" - The url from which will load the data
  • lv - Object with the data to send to the URL
  • "GET" - The method to send the data, can be "GET" or "POST"

We'll use this class to access S60 internal resources when using the code showed in this post to access this S60 resources.

Code example

In the below code we show how to access the GPS position using this solution.

//Fullscreen
fscommand2("FullScreen",true);
 
//Create the load vars variable
var lv:LoadVars = new LoadVars();
//Create a MovieClipLoader object to load the google static map
var loader:MovieClipLoader = new MovieClipLoader();
//Generate a API_KEY and set here.
var apiKey = 'ABQIAAAAJq0bIh_b5seBuaS5dG3MyBTgIMgsbASCAp5eBSzKUN4OpxTWjxQe25ul58fmeLTrIy1RiBxMJ2gJ5w';
//When the GPS position is retrieved. The following method is called.
lv.onLoad = function(success:Boolean){
if(success){
//Set the UI components with the retrieved data
//The retrieved data when you're accessing 'get_position' service are the 'latitude' and 'longitude' of the device.
latitude_txt.text = lv["latitude"].substring(0,8);
longitude_txt.text = lv["longitude"].substring(0,8);
var url:String = 'http://maps.google.com/staticmap?center='+trim(lv["latitude"].substring(0,8))+','+trim(lv["longitude"].substring(0,8))+'&zoom=10&size=220x200&maptype=mobile&key='+apiKey;
//Load a map with your position in the center
loader.loadClip(url,map_mc);
}else{
trace("Error");
}
}
//Start the work when press the 'LOAD MAP' button.
loadMap_btn.onPress = function(){
//The url gived in sendAndLoad method has access to the self device (127.0.0.1, to the port 5004 (This is the default port of the ServerPython) and the service 'get_position' (Retrieves the GPS position of the default module)
lv.sendAndLoad("http://127.0.0.1:5004/get_position",lv,"GET");
}

Remember that you have to start 'spython' application before the Flash Lite access S60 resources.

Download

Click here to download the complete example.

Other Links

To see more posts, go to Flash Lite Effort

108 page views in the last 30 days.