Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Phpforandroid en

306,865 views

Published on

Phpforandroid en

  1. 1. Ivan Mosquera <ivan@ivanmosquera.net> PHP for Android: PHP scripting on Android
  2. 2. 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
  3. 3. PHP for Android: scripting PHP en Android Slides ● http://www.slideshare.net/ivmos ● http://www.slideshare.net/irontec
  4. 4. 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.
  5. 5. PHP for Android: scripting PHP en Android Android ● Mobile OS. ● Opensource. ● 200.000 /day. ● → tablet
  6. 6. PHP for Android: scripting PHP en Android Android
  7. 7. PHP for Android: scripting PHP en Android Android
  8. 8. 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)
  9. 9. 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.
  10. 10. PHP for Android: scripting PHP en Android The problem ● API php → OK ● UI? (php-gtk?) ● Calls? ● Messages? ● Location? ● Sensors? ● ... ● Mobile web.
  11. 11. 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.
  12. 12. 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
  13. 13. 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.
  14. 14. PHP for Android: scripting PHP en Android APKs ● APKs: – SL4A – PFA ● SL4A detects PFA (intent filter).
  15. 15. 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
  16. 16. PHP for Android: scripting PHP en Android SL4A ● Script management. ● Android Facades. ● Interpreter install.
  17. 17. 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)
  18. 18. PHP for Android: scripting PHP en Android The Android class <?php include 'Android.php'; $droid = new Android(); public function __call($name, $args) { return $this->rpc($name, $args); } Json RPC
  19. 19. 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));
  20. 20. PHP for Android: scripting PHP en Android The Android class $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. 21. PHP for Android: scripting PHP en Android The Android class <?php require “Android.php”; $droid = new Android(); $droid->viewContacts();
  22. 22. PHP for Android: scripting PHP en Android “WhereAmI” script ● Location. ● Email building (google maps link).
  23. 23. 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,"longitud e":- 3.0339431,"latitude":43.3319985,"speed":0,"accuracy" :76,"altitude":0}}}
  24. 24. 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);
  25. 25. 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 : 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. 26. 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');
  27. 27. PHP for Android: scripting PHP en Android PFAf start locate credicts info
  28. 28. 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.
  29. 29. PHP for Android: scripting PHP en Android Script sharing ● SL4A scripts folder. ● Barcode (<4296 chars) ● Script on APK: – Template project → customize. – ANT
  30. 30. PHP for Android: scripting PHP en Android Roadmap ● SL4A – API extended. ● GUI... – Bugfixes. ● PFA – Sqlite,... phpize. – supporting SL4A releases.
  31. 31. PHP for Android: scripting PHP en Android ????? Questions Logo @Workoholics_

×