SlideShare a Scribd company logo
PHP for Android: PHP scripting on Android
$self ● Kinn Coelho Julião – Gerente de projetos - RPM – Instrutor PHP – 4Linux/DRC – PHP for Android Brasil project founder. – @kinncj
Index ● Android. – Introdução – Arquitetura ● PHP no Android ● Compilação do PHP ● SL4A & PhpForAndroid. ● Exemplo: script “WhereAmI”. – PFAf ● Desenvolvimento e compartilhamento ● Perguntas
Android ● Mobile OS.  ● Opensource. ● 200.000 /dia ● ->  tablet
Android
Android
PHP on Android ● Android “é” Linux. ● Então, deve funcionar – É claro que sim... ● ARM cross compiling. ● Método 1 (fécil): – Compilação estática gnu libc (> 7MB)
PHP on Android ● Caminho não tão fácil: – Lincado a libc Bionic. ● Bionic: libc do Android – BSD. – sizeof(gnu_libc) * 0.5 – Documentação incompleta. ● PHP no Android. – Php-cli sapi – Agcc  – Tweaks devido o bionic. – =~ 2MB – Sockets, json.
The problem ● API php -> OK ● UI? (php-gtk?) ● Chamadas? ● Mensagens? ● Localização? ● Sensores? ● ... ● Mobile web.
The solution ● Google project (Damon Kohler), opensource. ● SL4A (Scripting Layer For Android)  ● Android app (APK). ● Camada para linguagens Scripts ● Expõe a API Android ● Realmente ativos, liberam sempre
The solution ● Oficialmente suporta as linguagens: – Python. – Perl. – Ruby. – Lua... ● Para cada interpretador -> APK installer.
The PFA project ● ● @phpforandroid ● SL4A PHP support. ● APK. ● Android PHP binary. ● Framework. ● Free software. Http://www.phpforandroid.net
The PFA project ● http://www.php4android.com.br ● HowTo's ● News ● PT-BR Support
APKs ● APKs: – SL4A – PFA ● SL4A detecta PFA (Intenção de filtro)
PHP for Android ● Installer (that's all folks): – PHP bin. ● php_rX.zip – Scripts ● php_scripts_rX.zip – Misc ● Android.php ● php.ini ● php_extras_rX.zip
SL4A ● Gerenciamento dos Scripts. ● Android Facades. ● Instalação do interpretador.
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)
The Android class <?php include 'Android.php'; $droid = new Android(); public function __call($name, $args) { return $this->rpc($name, $args); } Json RPC
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));
The Android class $response = socket_read($this->_socket, 1024,  PHP_NORMAL_READ) or die(&quot;Could not read  input\n&quot;);  $this->_id++; $result =  json_decode ($response); return  array ('id' => $result-> id , 'result' => $result-> result , 'error' => $result-> error ); }
The Android class <?php require “Android.php”; $droid = new Android(); $droid->viewContacts();
“ WhereAmI” script ● Localização ● Email building (link do maps).
“ WhereAmI” script $droid-> startLocating (); – Received: {&quot;id&quot;:24,&quot;method&quot;:&quot;startLocating&quot;,&quot;params&quot;:[]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:24,&quot;result&quot;:null} $location = $droid-> readLocation (); – Received: {&quot;id&quot;:25,&quot;method&quot;:&quot;readLocation&quot;,&quot;params&quot;:[]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:25,&quot;result&quot;:{&quot;network&quot;: {&quot;provider&quot;:&quot;network&quot;,&quot;time&quot;:1288215482448,&quot;longitud e&quot;:- 46.6167,&quot;latitude&quot;:-23.5333,&quot;speed&quot;:0,&quot;accuracy&quot; :76,&quot;altitude&quot;:0}}}
“ WhereAmI” script $droid-> stopLocating (); – Received: {&quot;id&quot;:26,&quot;method&quot;:&quot;stopLocating&quot;,&quot;params&quot;:[]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:26,&quot;result&quot;:null} $longitude =  $location[&quot;result&quot;]->network->longitude; $latitude =  $location[&quot;result&quot;]->network->latitude; $mapLink = sprintf('http://maps.google.com/maps? q=%s,%s', $latitude, $longitude);
“ WhereAmI” script $data .= &quot;Google maps : $mapLink&quot;; $droid-> sendEmail ('', 'To aqui Rapeize ', $data ); – Received: {&quot;id&quot;:29,&quot;method&quot;:&quot;sendEmail&quot;,&quot;params&quot;: [&quot;&quot;,&quot;Donde estoy&quot;,&quot;admin_area : Sao Paulo \nfeature_name : 3 \nsub_admin_area : Sao Paulo  \npostal_code : 04002033 \nlocality : Sao Paulo  \nthoroughfare : 4Linux  \ncountry_code : BR \ncountry_name : Brazil  \n\nGoogle Maps: https:\/\/p.rizon.top:443\/http\/maps.google.com\/maps? q=-23.5333, -46.6167&quot;]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:29,&quot;result&quot;:null}
PFAf ● Maciej Wilgucki @wilgucki ● Framework disponível desde o PFA 0.3. ● Estenda a parte Abstrada, implementa o init ● Organiza seu script com estados ● function FooAction() { .... $this->setNextAction('bar');
PFAf Início Créditos Informação
Development environment ● SL4A... – Emulador, adb. ● [allow_url_fopen, allow_url_include] -> ON – testnow.php – testcache.php ● Remote scripting.
Script sharing ● SL4A scripts folder. ● Barcode (<4296 chars) ● Script on APK: – Template project -> customize. – ANT
Roadmap ● SL4A – API extended. ● GUI... – Bugfixes. ● PFA – Sqlite,... phpize. – supporting SL4A releases.
????? Perguntas? Logo @Workoholics_

More Related Content

PDF
Montreal.rb ruby debugging basics - march 20th 2012
ODP
Untitled talk at Riviera.rb
PDF
Lately in php - 2019 May 4
PDF
Last 2 Months in PHP - July & August 2016
PDF
My talk at LVEE 2016
PDF
PSR7 - interoperabilità HTTP
PDF
Idiomatic R for Rosetta Code (2013)
PDF
OVHcloud TechTalks - ML serving
Montreal.rb ruby debugging basics - march 20th 2012
Untitled talk at Riviera.rb
Lately in php - 2019 May 4
Last 2 Months in PHP - July & August 2016
My talk at LVEE 2016
PSR7 - interoperabilità HTTP
Idiomatic R for Rosetta Code (2013)
OVHcloud TechTalks - ML serving

What's hot (17)

PDF
Fuzzing softwares for bugs - OWASP Seasides
PDF
prototype::signatures
PPTX
Resful Trinity Code One - San Francisco
PDF
Tdd presentation
PDF
Last Month in PHP - June through Mid-July 2017
PDF
Chasing the RESTful Trinity - Client CLI and Documentation
PDF
Spring-batch Groovy y Gradle
PDF
Metasepi team meeting #7: Snatch application on tiny OS
PDF
Go, meet Lua
PDF
Go at Skroutz
PDF
Terraform & IaC - Nam CXN
PDF
really really really awesome php application with bdd behat and iterfaces
PDF
GraalVM and MicroProfile - A Polyglot Microservices Solution
PDF
Flutter beers and pizza
PDF
Jedi knight
PDF
Coding Dojo: Roman Numerals (2014)
ODP
Special Subject 1+2: RoR 1
Fuzzing softwares for bugs - OWASP Seasides
prototype::signatures
Resful Trinity Code One - San Francisco
Tdd presentation
Last Month in PHP - June through Mid-July 2017
Chasing the RESTful Trinity - Client CLI and Documentation
Spring-batch Groovy y Gradle
Metasepi team meeting #7: Snatch application on tiny OS
Go, meet Lua
Go at Skroutz
Terraform & IaC - Nam CXN
really really really awesome php application with bdd behat and iterfaces
GraalVM and MicroProfile - A Polyglot Microservices Solution
Flutter beers and pizza
Jedi knight
Coding Dojo: Roman Numerals (2014)
Special Subject 1+2: RoR 1
Ad

Viewers also liked (20)

PPTX
Overzicht gebruik sociale media verkiezingen 2012 Verenigde Staten
PPT
Proyecto Facebook – DimensióN ParticipacióN
PDF
Benaulim india
PDF
Mot so bai_toan_khac_ve_thoi_gian
PPT
Azotea de finca mackey
PPS
Que Lado Del Cerebro Usas?
PDF
Aydinlatma direkleri temel temel detaylari
PPTX
Behaviour modelling
PDF
Npc force weekly 21 may 25 may 2012
PDF
GTMS. Atenció a la dependència DAP Costa de Ponent
PPTX
팀원과 정기면담, 도란도란 사례공유
PPTX
WebRTC, another Web?
PPTX
RoboCV Module 5: Contours using OpenCV
DOC
Bai tap phan ung oxi hoa lop 10
PDF
Vnx.su vesta-trud
PDF
TADHack London, Igor Pavlov, Showcase, When your fingers get tired… jump into...
PDF
Vnx.su lada 2170 tpудоемкость
PDF
Vnx.su особенности суд ваз-21126
PPTX
Student management system
PDF
TADHack London, Distillate, Roderick Hodgson & Alex Francois, Telestax, Dialo...
Overzicht gebruik sociale media verkiezingen 2012 Verenigde Staten
Proyecto Facebook – DimensióN ParticipacióN
Benaulim india
Mot so bai_toan_khac_ve_thoi_gian
Azotea de finca mackey
Que Lado Del Cerebro Usas?
Aydinlatma direkleri temel temel detaylari
Behaviour modelling
Npc force weekly 21 may 25 may 2012
GTMS. Atenció a la dependència DAP Costa de Ponent
팀원과 정기면담, 도란도란 사례공유
WebRTC, another Web?
RoboCV Module 5: Contours using OpenCV
Bai tap phan ung oxi hoa lop 10
Vnx.su vesta-trud
TADHack London, Igor Pavlov, Showcase, When your fingers get tired… jump into...
Vnx.su lada 2170 tpудоемкость
Vnx.su особенности суд ваз-21126
Student management system
TADHack London, Distillate, Roderick Hodgson & Alex Francois, Telestax, Dialo...
Ad

Similar to Php4android TDC 2011 (6)

PDF
Phpforandroid en
ODP
PHP for Android: prototyping Android apps in php
ODP
When Perl Met Android (YAPC::EU 2010)
KEY
Android Scripting
PDF
InspiringCon14: ElePHPants on speed: Running TYPO3 Flow on HipHop VM
PPT
Building PHP Powered Android Applications
Phpforandroid en
PHP for Android: prototyping Android apps in php
When Perl Met Android (YAPC::EU 2010)
Android Scripting
InspiringCon14: ElePHPants on speed: Running TYPO3 Flow on HipHop VM
Building PHP Powered Android Applications

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced IT Governance
PDF
Chapter 2 Digital Image Fundamentals.pdf
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
GamePlan Trading System Review: Professional Trader's Honest Take
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Understanding_Digital_Forensics_Presentation.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
20250228 LYD VKU AI Blended-Learning.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced IT Governance
Chapter 2 Digital Image Fundamentals.pdf
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
KodekX | Application Modernization Development

Php4android TDC 2011

  • 1. PHP for Android: PHP scripting on Android
  • 2. $self ● Kinn Coelho Julião – Gerente de projetos - RPM – Instrutor PHP – 4Linux/DRC – PHP for Android Brasil project founder. – @kinncj
  • 3. Index ● Android. – Introdução – Arquitetura ● PHP no Android ● Compilação do PHP ● SL4A & PhpForAndroid. ● Exemplo: script “WhereAmI”. – PFAf ● Desenvolvimento e compartilhamento ● Perguntas
  • 4. Android ● Mobile OS. ● Opensource. ● 200.000 /dia ● -> tablet
  • 7. PHP on Android ● Android “é” Linux. ● Então, deve funcionar – É claro que sim... ● ARM cross compiling. ● Método 1 (fécil): – Compilação estática gnu libc (> 7MB)
  • 8. PHP on Android ● Caminho não tão fácil: – Lincado a libc Bionic. ● Bionic: libc do Android – BSD. – sizeof(gnu_libc) * 0.5 – Documentação incompleta. ● PHP no Android. – Php-cli sapi – Agcc – Tweaks devido o bionic. – =~ 2MB – Sockets, json.
  • 9. The problem ● API php -> OK ● UI? (php-gtk?) ● Chamadas? ● Mensagens? ● Localização? ● Sensores? ● ... ● Mobile web.
  • 10. The solution ● Google project (Damon Kohler), opensource. ● SL4A (Scripting Layer For Android) ● Android app (APK). ● Camada para linguagens Scripts ● Expõe a API Android ● Realmente ativos, liberam sempre
  • 11. The solution ● Oficialmente suporta as linguagens: – Python. – Perl. – Ruby. – Lua... ● Para cada interpretador -> APK installer.
  • 12. The PFA project ● ● @phpforandroid ● SL4A PHP support. ● APK. ● Android PHP binary. ● Framework. ● Free software. Http://www.phpforandroid.net
  • 13. The PFA project ● http://www.php4android.com.br ● HowTo's ● News ● PT-BR Support
  • 14. APKs ● APKs: – SL4A – PFA ● SL4A detecta PFA (Intenção de filtro)
  • 15. PHP for Android ● Installer (that's all folks): – PHP bin. ● php_rX.zip – Scripts ● php_scripts_rX.zip – Misc ● Android.php ● php.ini ● php_extras_rX.zip
  • 16. SL4A ● Gerenciamento dos Scripts. ● Android Facades. ● Instalação do interpretador.
  • 17. 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. The Android class <?php include 'Android.php'; $droid = new Android(); public function __call($name, $args) { return $this->rpc($name, $args); } Json RPC
  • 19. 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. The Android class $response = socket_read($this->_socket, 1024, PHP_NORMAL_READ) or die(&quot;Could not read input\n&quot;); $this->_id++; $result = json_decode ($response); return array ('id' => $result-> id , 'result' => $result-> result , 'error' => $result-> error ); }
  • 21. The Android class <?php require “Android.php”; $droid = new Android(); $droid->viewContacts();
  • 22. “ WhereAmI” script ● Localização ● Email building (link do maps).
  • 23. “ WhereAmI” script $droid-> startLocating (); – Received: {&quot;id&quot;:24,&quot;method&quot;:&quot;startLocating&quot;,&quot;params&quot;:[]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:24,&quot;result&quot;:null} $location = $droid-> readLocation (); – Received: {&quot;id&quot;:25,&quot;method&quot;:&quot;readLocation&quot;,&quot;params&quot;:[]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:25,&quot;result&quot;:{&quot;network&quot;: {&quot;provider&quot;:&quot;network&quot;,&quot;time&quot;:1288215482448,&quot;longitud e&quot;:- 46.6167,&quot;latitude&quot;:-23.5333,&quot;speed&quot;:0,&quot;accuracy&quot; :76,&quot;altitude&quot;:0}}}
  • 24. “ WhereAmI” script $droid-> stopLocating (); – Received: {&quot;id&quot;:26,&quot;method&quot;:&quot;stopLocating&quot;,&quot;params&quot;:[]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:26,&quot;result&quot;:null} $longitude = $location[&quot;result&quot;]->network->longitude; $latitude = $location[&quot;result&quot;]->network->latitude; $mapLink = sprintf('http://maps.google.com/maps? q=%s,%s', $latitude, $longitude);
  • 25. “ WhereAmI” script $data .= &quot;Google maps : $mapLink&quot;; $droid-> sendEmail ('', 'To aqui Rapeize ', $data ); – Received: {&quot;id&quot;:29,&quot;method&quot;:&quot;sendEmail&quot;,&quot;params&quot;: [&quot;&quot;,&quot;Donde estoy&quot;,&quot;admin_area : Sao Paulo \nfeature_name : 3 \nsub_admin_area : Sao Paulo \npostal_code : 04002033 \nlocality : Sao Paulo \nthoroughfare : 4Linux \ncountry_code : BR \ncountry_name : Brazil \n\nGoogle Maps: https:\/\/p.rizon.top:443\/http\/maps.google.com\/maps? q=-23.5333, -46.6167&quot;]} – Sent: {&quot;error&quot;:null,&quot;id&quot;:29,&quot;result&quot;:null}
  • 26. PFAf ● Maciej Wilgucki @wilgucki ● Framework disponível desde o PFA 0.3. ● Estenda a parte Abstrada, implementa o init ● Organiza seu script com estados ● function FooAction() { .... $this->setNextAction('bar');
  • 27. PFAf Início Créditos Informação
  • 28. Development environment ● SL4A... – Emulador, adb. ● [allow_url_fopen, allow_url_include] -> ON – testnow.php – testcache.php ● Remote scripting.
  • 29. Script sharing ● SL4A scripts folder. ● Barcode (<4296 chars) ● Script on APK: – Template project -> customize. – ANT
  • 30. Roadmap ● SL4A – API extended. ● GUI... – Bugfixes. ● PFA – Sqlite,... phpize. – supporting SL4A releases.
  • 31. ????? Perguntas? Logo @Workoholics_