php for android: scripting php en android
TRANSCRIPT
![Page 2: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/2.jpg)
PHP for Android: scripting PHP en Android
$self
● Iván Mosquera– ZCE– PHP, Java, C.– Fundador proyecto PHP for Android.– @ivmos
● Irontec– Consultoría software libre.– Desarrollo/Sistemas/VoIp/Formación.– @irontec
![Page 3: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/3.jpg)
PHP for Android: scripting PHP en Android
Presentación
● http://www.slideshare.net/ivmos● http://www.slideshare.net/irontec
![Page 4: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/4.jpg)
PHP for Android: scripting PHP en Android
Index
● Android.– Introducción.– Arquitectura.
● PHP en Android● Compilación PHP.● SL4A y PhpForAndroid.
● Ejemplo: script “DondeEstoy”.– PFAf
● Desarrollo y distribución.● Ruegos y preguntas.
![Page 5: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/5.jpg)
PHP for Android: scripting PHP en Android
Android
● OS móvil. ● Libre● 200.000 activaciones/día.● Hacia el tablet?
![Page 6: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/6.jpg)
PHP for Android: scripting PHP en Android
Android
![Page 7: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/7.jpg)
PHP for Android: scripting PHP en Android
Android
![Page 8: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/8.jpg)
PHP for Android: scripting PHP en Android
PHP en Android
● Android “es” Linux.● php debería funcionar...
– Y claro que funciona.● Compilación cruzada ARM.● Método 1 (sencillo):
– Compilación estática gnu libc (> 7MB)
![Page 9: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/9.jpg)
PHP for Android: scripting PHP en Android
PHP en Android
● Método no tan fácil:– Linkado a bionic.
● Bionic: libc de Android– BSD.– sizeof(gnu_libc) * 0.5– Ciertas carencias.
● PHP en Android.– Php-cli sapi– Agcc – Tweaks por bionic.– =~ 2MB– Sockets, json.
![Page 10: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/10.jpg)
PHP for Android: scripting PHP en Android
El problema
● API php → OK● UI? (php-gtk?)● Llamar?● Mensajes?● Geolocalización?● Sensores?● ...
● Web móvil...
![Page 11: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/11.jpg)
PHP for Android: scripting PHP en Android
La solución
● Proyecto Google (Damon Kohler), libre.● SL4A (Scripting Layer For Android) (antes ASE)● Aplicación Android (APK).● Capa intermedia para lenguajes scripting.● Expone parte del API de Android.● Muy activo, releases frecuentes.
![Page 12: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/12.jpg)
PHP for Android: scripting PHP en Android
La solución
● Lenguajes soportados oficialmente:– Python.– Perl.– Ruby.– Lua...
● Cada intérprete → instalador APK.● PHP? → incidencia #40 → phpforandroid.net
http://code.google.com/p/android-scripting/issues/detail?id=40
![Page 13: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/13.jpg)
PHP for Android: scripting PHP en Android
The PFA project
● Http://www.phpforandroid.net● @phpforandroid● Soporte PHP a SL4A.● Mantener APK.● Mantener binario PHP para Android.● Mantener framework.● Comunidad, libre.
![Page 14: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/14.jpg)
PHP for Android: scripting PHP en Android
APKs
● Dos APKs:– SL4A– PFA
● SL4A detectaPFA con unintent filter.
![Page 15: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/15.jpg)
PHP for Android: scripting PHP en Android
PHP for Android
● Instalador:– Binario PHP.
● php_rX.zip
– Scripts● php_scripts_rX.zip
– Otros● Android.php● php.ini● php_extras_rX.zip
![Page 16: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/16.jpg)
PHP for Android: scripting PHP en Android
SL4A
● Administración de scripts.● Android Facades.● Instalación intérpretes.
![Page 17: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/17.jpg)
PHP for Android: scripting PHP en Android
PHP for Android y 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)
![Page 18: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/18.jpg)
PHP for Android: scripting PHP en Android
La clase Android
<?phpinclude 'Android.php';$droid = new Android();
public function __call($name, $args) { return $this->rpc($name, $args);}
Json RPC
![Page 19: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/19.jpg)
PHP for Android: scripting PHP en Android
La clase Android
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));
![Page 20: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/20.jpg)
PHP for Android: scripting PHP en Android
La clase Android
$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 ); }
![Page 21: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/21.jpg)
PHP for Android: scripting PHP en Android
La clase Android
<?phprequire “Android.php”;$droid = new Android();$droid->viewContacts();
![Page 22: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/22.jpg)
PHP for Android: scripting PHP en Android
Un ejemplo: script “DondeEstoy”
● Detectar geolocalización.● Construir SMS || Email.
![Page 23: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/23.jpg)
PHP for Android: scripting PHP en Android
Un ejemplo: script “DondeEstoy”
$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}}}
![Page 24: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/24.jpg)
PHP for Android: scripting PHP en Android
Un ejemplo: script “DondeEstoy”
$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);
![Page 25: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/25.jpg)
PHP for Android: scripting PHP en Android
Un ejemplo: script “DondeEstoy”
$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}
![Page 26: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/26.jpg)
PHP for Android: scripting PHP en Android
PFAf
● Maciej Wilgucki @wilgucki● Framework incluido en PFA desde 0.3.● Extender ScriptAbstract, implementar init.● Organizar script como MAE (estados).● Desde cada FooAction
– $this->setNextAction('bar');
![Page 27: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/27.jpg)
PHP for Android: scripting PHP en Android
PFAf
start
locate
credicts
info
![Page 28: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/28.jpg)
PHP for Android: scripting PHP en Android
Entorno desarrollo
● Desde SL4A...– Emulador: adb.
● [allow_url_fopen, allow_url_include] → ON– testnow.php– testcache.php
● Ejecución remota.
![Page 29: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/29.jpg)
PHP for Android: scripting PHP en Android
Distribución de scripts
● Carpeta scripts de SL4A.● Barcode (<4296 chars)● Script en APK:
– Parametrización proyecto Plantilla.– ANT
![Page 30: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/30.jpg)
PHP for Android: scripting PHP en Android
Roadmap
● SL4A– Ampliación API.
● GUI
– Estabilización.● PFA
– Sqlite,... phpize.– Siguiendo SL4A.
![Page 31: PHP for Android: scripting PHP en Android](https://reader034.vdocuments.mx/reader034/viewer/2022052202/557acb2fd8b42a2c0f8b4b11/html5/thumbnails/31.jpg)
PHP for Android: scripting PHP en Android
?????
Ruegos y preguntas
Logo @Workoholics_