phpforandroid en
TRANSCRIPT
Ivan Mosquera <[email protected]>
PHP for Android: PHP scripting on Android
PHP for Android: scripting PHP en Android
$self
● Iván Mosquera– ZCE– PHP, Java, C.– PHP for Android project founder.– @ivmos
● Irontec– Free software company.– Development/Systems/VoIp/Learning.– @irontec
PHP for Android: scripting PHP en Android
Slides
● http://www.slideshare.net/ivmos● http://www.slideshare.net/irontec
PHP for Android: scripting PHP en Android
Index
● Android.– Intro..– Architecture.
● PHP on Android● PHP compilation.● SL4A & PhpForAndroid.
● Example: script “WhereAmI”.– PFAf
● Development and sharing.● Questions.
PHP for Android: scripting PHP en Android
Android
● Mobile OS. ● Opensource.● 200.000 /day.● → tablet
PHP for Android: scripting PHP en Android
Android
PHP for Android: scripting PHP en Android
Android
PHP for Android: scripting PHP en Android
PHP on Android
● Android “is” Linux.● So it should work.
– Of course it does..● ARM cross compiling.● Method 1 (easy):
– Static compilation gnu libc (> 7MB)
PHP for Android: scripting PHP en Android
PHP en Android
● Not so easy way:– Linked to Bionic.
● Bionic: libc de Android– BSD.– sizeof(gnu_libc) * 0.5– Missing stuff.
● PHP on Android.– Php-cli sapi– Agcc – Tweaks because of bionic.– =~ 2MB– Sockets, json.
PHP for Android: scripting PHP en Android
The problem
● API php → OK● UI? (php-gtk?)● Calls?● Messages?● Location?● Sensors?● ...
● Mobile web.
PHP for Android: scripting PHP en Android
The solution
● Google project (Damon Kohler), opensource.● SL4A (Scripting Layer For Android) ● Android app (APK).● Layer for scripting languages.● Exposes Android API.● Really active, often releases.
PHP for Android: scripting PHP en Android
The solution
● Officially supported languages:– Python.– Perl.– Ruby.– Lua...
● Foreach interpreter → APK installer.● PHP? → issue #40 → phpforandroid.net
http://code.google.com/p/android-scripting/issues/detail?id=40
PHP for Android: scripting PHP en Android
The PFA project
● Http://www.phpforandroid.net● @phpforandroid● SL4A PHP support.● APK.● Android PHP binary.● Framework.● Free software.
PHP for Android: scripting PHP en Android
APKs
● APKs:– SL4A– PFA
● SL4A detects PFA(intent filter).
PHP for Android: scripting PHP en Android
PHP for Android
● Installer (that's all):– PHP bin.
● php_rX.zip
– Scripts● php_scripts_rX.zip
– Misc● Android.php● php.ini● php_extras_rX.zip
PHP for Android: scripting PHP en Android
SL4A
● Script management.● Android Facades.● Interpreter install.
PHP for Android: scripting PHP en Android
PHP for Android & SL4A
● 0.1 (ASE r26 unofficial, php 5.3.3rc2)● 0.2 (SL4A_r0, php 5.3.3rc3)● 0.3 (SL4A_r2+, php 5.3.3)
PHP for Android: scripting PHP en Android
The Android class
<?phpinclude 'Android.php';$droid = new Android();
public function __call($name, $args) { return $this->rpc($name, $args);}
Json RPC
PHP for Android: scripting PHP en Android
The Android class
public function rpc($method, $args) { $data = array( 'id'=>$this->_id, 'method'=>$method, 'params'=>$args ); $request = json_encode($data) . “\n”; $sent = socket_write($this->_socket, $request, strlen($request));
PHP for Android: scripting PHP en Android
The Android class
$response = socket_read($this->_socket, 1024, PHP_NORMAL_READ) or die("Could not read input\n"); $this->_id++; $result = json_decode($response);
return array ('id' => $result->id, 'result' => $result->result, 'error' => $result->error ); }
PHP for Android: scripting PHP en Android
The Android class
<?phprequire “Android.php”;$droid = new Android();$droid->viewContacts();
PHP for Android: scripting PHP en Android
“WhereAmI” script
● Location.● Email building (google maps link).
PHP for Android: scripting PHP en Android
“WhereAmI” script
$droid->startLocating();– Received: {"id":24,"method":"startLocating","params":[]}– Sent: {"error":null,"id":24,"result":null}
$location = $droid->readLocation();– Received: {"id":25,"method":"readLocation","params":[]}– Sent: {"error":null,"id":25,"result":{"network":
{"provider":"network","time":1288215482448,"longitude":-3.0339431,"latitude":43.3319985,"speed":0,"accuracy":76,"altitude":0}}}
PHP for Android: scripting PHP en Android
“WhereAmI” script
$droid->stopLocating();– Received: {"id":26,"method":"stopLocating","params":[]}– Sent: {"error":null,"id":26,"result":null}
$longitude = $location["result"]->network->longitude;$latitude = $location["result"]->network->latitude;$mapLink = sprintf('http://maps.google.com/maps?q=%s,%s', $latitude, $longitude);
PHP for Android: scripting PHP en Android
“WhereAmI” script
$data .= "Google maps : $mapLink";$droid->sendEmail('', 'Donde estoy', $data );
– Received: {"id":29,"method":"sendEmail","params":["","Donde estoy","admin_area : Pa\u00eds Vasco \nfeature_name : 3 \nsub_admin_area : Vizcaya \npostal_code : 48980 \nlocality : Santurtzi \nthoroughfare : Calle del Puerto Pesquero \ncountry_code : ES \ncountry_name : Espa\u00f1a \n\nGoogle Maps: http:\/\/maps.google.com\/maps?q=13.3319985, 6.0339431"]}
– Sent: {"error":null,"id":29,"result":null}
PHP for Android: scripting PHP en Android
PFAf
● Maciej Wilgucki @wilgucki● Framework avaiblable since PFA 0.3.● Extend ScriptAbstract, implement init.● Organize your script with states.● function FooAction() {
....$this->setNextAction('bar');
PHP for Android: scripting PHP en Android
PFAf
start
locate
credicts
info
PHP for Android: scripting PHP en Android
Development environment
● SL4A...– Emulator, adb.
● [allow_url_fopen, allow_url_include] → ON– testnow.php– testcache.php
● Remote scripting.
PHP for Android: scripting PHP en Android
Script sharing
● SL4A scripts folder.● Barcode (<4296 chars)● Script on APK:
– Template project → customize.– ANT
PHP for Android: scripting PHP en Android
Roadmap
● SL4A– API extended.
● GUI...
– Bugfixes.● PFA
– Sqlite,... phpize.– supporting SL4A releases.
PHP for Android: scripting PHP en Android
?????
Questions
Logo @Workoholics_