Your SlideShare is downloading. ×
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
PHP for Android: scripting PHP en Android
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

PHP for Android: scripting PHP en Android

7,342

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,342
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
142
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ivan Mosquera <ivan@ivanmosquera.net> PHP for Android: scripting PHP en Android
  • 2. 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
  • 3. PHP for Android: scripting PHP en Android Presentación ● http://www.slideshare.net/ivmos ● http://www.slideshare.net/irontec
  • 4. 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.
  • 5. PHP for Android: scripting PHP en Android Android ● OS móvil. ● Libre ● 200.000 activaciones/día. ● Hacia el tablet?
  • 6. PHP for Android: scripting PHP en Android Android
  • 7. PHP for Android: scripting PHP en Android Android
  • 8. 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)
  • 9. 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.
  • 10. PHP for Android: scripting PHP en Android El problema ● API php → OK ● UI? (php-gtk?) ● Llamar? ● Mensajes? ● Geolocalización? ● Sensores? ● ... ● Web móvil...
  • 11. 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.
  • 12. 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
  • 13. 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.
  • 14. PHP for Android: scripting PHP en Android APKs ● Dos APKs: – SL4A – PFA ● SL4A detecta PFA con un intent filter.
  • 15. 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
  • 16. PHP for Android: scripting PHP en Android SL4A ● Administración de scripts. ● Android Facades. ● Instalación intérpretes.
  • 17. 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)
  • 18. PHP for Android: scripting PHP en Android La clase Android <?php include 'Android.php'; $droid = new Android(); public function __call($name, $args) { return $this->rpc($name, $args); } Json RPC
  • 19. 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));
  • 20. PHP for Android: scripting PHP en Android La clase Android $response = socket_read($this->_socket, 1024, PHP_NORMAL_READ) or die("Could not read inputn"); $this->_id++; $result = json_decode($response); return array ('id' => $result->id, 'result' => $result->result, 'error' => $result->error ); }
  • 21. PHP for Android: scripting PHP en Android La clase Android <?php require “Android.php”; $droid = new Android(); $droid->viewContacts();
  • 22. PHP for Android: scripting PHP en Android Un ejemplo: script “DondeEstoy” ● Detectar geolocalización. ● Construir SMS || Email.
  • 23. 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,"longitud e":- 3.0339431,"latitude":43.3319985,"speed":0,"accuracy" :76,"altitude":0}}}
  • 24. 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);
  • 25. 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 : Pau00eds Vasco nfeature_name : 3 nsub_admin_area : Vizcaya npostal_code : 48980 nlocality : Santurtzi nthoroughfare : Calle del Puerto Pesquero ncountry_code : ES ncountry_name : Espau00f1a nnGoogle Maps: http://maps.google.com/maps? q=13.3319985, 6.0339431"]} – Sent: {"error":null,"id":29,"result":null}
  • 26. 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');
  • 27. PHP for Android: scripting PHP en Android PFAf start locate credicts info
  • 28. 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.
  • 29. 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
  • 30. PHP for Android: scripting PHP en Android Roadmap ● SL4A – Ampliación API. ● GUI – Estabilización. ● PFA – Sqlite,... phpize. – Siguiendo SL4A.
  • 31. PHP for Android: scripting PHP en Android ????? Ruegos y preguntas Logo @Workoholics_

×