SlideShare a Scribd company logo
PHP for Android
Prototyping Android apps in php
Cesare D'Amico
cesare@wyrd.it
Cesare D'Amico
freelance php dev
Hi, nice to meet you!
cesare@wyrd.it
Twitter: __ce (double underscore)
http://cesaredami.co/
What happens adding...
+
Genetically modified php :)
We're going to talk about...
+ PFAf
SL4A
Android
Android
• built on top of a linux
kernel
• native libc (Bionic):
0.5 * sizeof(GNU libC)
• runtime (Dalvik VM) +
system libs
• application framework
• Java!
How can we make php run
on Android?
1. static compilation with Glibc (over
7MB)... fat!
2. linked to Bionic: smaller (~2MB), but
tweaks needed
How can we make php run
on Android?
3. SL4A to the rescue!
SL4A – scripting layer for
Android
• Google project, led by
Damon Kohler
• Open Source
• exposes Android API
• quite active
SL4A: installation
As easy as:
1) enable “Unknown
sources” under Applications
settings
2)
PHP for Android project
• led by Iván Mosquera,
software engineer at Irontec
(the people behind IronPython
and other OS projects)
• Open Source
• Started in 2009
• php-for-android on Google
Groups
PFA: installation
The PFA apk just installs
other components:
• php_rX.zip:
– php binary
• php_scripts_rX.zip
– scripts and PFAf
• php_extras_rX.zip
• Android.php + php.ini
Everything's installed!
SL4A: how does it work?
Provides Android facades
Makes the Android API
available through JSON
RPC calls
PFA: let's try it
PFA: let's try it
<?php
require_once('Android.php');
$droid = new Android();
$droid­>vibrate();
PFA: let's try it
SOOOO easy! :-)
PFA: let's try it
Let's try
something
else:
PFA: let's try it
<?php
require_once('Android.php');
$droid = new Android();
$name = $droid­>getInput('Hi!',
  'What is your name?');
$droid­>makeToast('Hello '.
  $name['result']);
PFA: let's try it
PFA: access phone features
PFA: access phone features
<?php
require_once('Android.php');
$droid = new Android();
$droid­>viewContacts();
PFA: access phone features
Many more features
available; API full list:
http://j.mp/9btqUG
Examples: smsSend, sendEmail,
cameraCapturePicture, viewHTML,
bluetoothConnect, contactsGet,
viewMap... (perhaps not *everything*
available yet)
PFA: writing scripts
Directly on the phone!
PFA: writing scripts
SOOOOO
slow and
unusable!
:-(
PFA: writing scripts
Including local files:
<?php
include('/sdcard/proj/...');
?>
PFA: writing scripts
allow_url_fopen
+
allow_url_include
FTW!
PFA: including remote code
<?php
require_once('Android.php');
$droid = new Android();
include('http://www.wyrd.it/
droid.php.txt');
<?php
$droid­>makeToast("There's a 
starman waiting in the sky!");
remote.php
droid.php.txt
PFA: including remote code
PFA: including remote code
include('http://www.wyrd.it/
droid.php.txt');
Secure
Handy
?
This is here for testing purposes ONLY!
PFA: including remote code
Don't forget that PFA,
although yet useable in
many respects, is still
alpha software.
In the future we'll be
able to distribute scripts
in apk format, without
using allow_url_fopen
PFA: internals
Android.php:
<?php
public function __call($name, $args){
  return $this­>rpc($name, $args);
}
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));
PFA: internals
<?php
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));
  $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']
  );
}
PFAf: PFA framework
Base php class: ScriptAbstract; apps
extend this class and implement init()
States-based: put on a stack the next
action you want to execute
function currentAction(){
  ...
  $this­>setNextAction('next');
}
function nextAction() { ... }
Thanks everyone!
?
PFA wants you!
You can help by writing
scripts and sharing
them:
http://www.phpforandroid.net/scripts
...and there are good examples there!
Take a look at the wi-fi scanner and the
web server ;)
12-14 Maggio 2011
http://www.phpday.it/
Please, rate this talk!
Feel like bashing?
Urge saying you fell in love
with this presentation?
Now you can!
http://joind.in/2152

More Related Content

What's hot (20)

PDF
Pavimentando el Camino con Jakarta EE 9 y Apache TomEE 9.0.0
César Hernández
 
PDF
JavaScript for PHP Developers
funkatron
 
PDF
Flutter beers and pizza
Jon Durán
 
PDF
Spring-batch Groovy y Gradle
Antonio Mas
 
PDF
RxNetty
Diego Pacheco
 
PDF
7 recomendaciones para migrar tus aplicaciones a Jakarta EE utilizando Apache...
César Hernández
 
PDF
DBI for Parrot and Perl 6 Lightning Talk 2007
Tim Bunce
 
PDF
Paving the road with Jakarta EE and Apache TomEE - JCON 2021
César Hernández
 
PDF
PSR7 - interoperabilità HTTP
Massimiliano Arione
 
PPTX
C/C++ Remote Development Overview
Thitipong Jampajeen
 
PDF
Building Command Line Tools with Golang
Takaaki Mizuno
 
PDF
plone.api
gilforcada
 
PDF
Beyond QA
gilforcada
 
PDF
Let the contribution begin
SeongJae Park
 
PDF
Best practices for joomla extensions developers
Francesco Abeni
 
PDF
用 Go 語言實戰 Push Notification 服務
Bo-Yi Wu
 
PDF
Code analysis for a better future
gilforcada
 
PDF
Creating an api from design to security.
Roan Brasil Monteiro
 
PDF
Pavimentando el camino con Jakarta EE 9 y Apache TomEE
César Hernández
 
PDF
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
Nexus FrontierTech
 
Pavimentando el Camino con Jakarta EE 9 y Apache TomEE 9.0.0
César Hernández
 
JavaScript for PHP Developers
funkatron
 
Flutter beers and pizza
Jon Durán
 
Spring-batch Groovy y Gradle
Antonio Mas
 
RxNetty
Diego Pacheco
 
7 recomendaciones para migrar tus aplicaciones a Jakarta EE utilizando Apache...
César Hernández
 
DBI for Parrot and Perl 6 Lightning Talk 2007
Tim Bunce
 
Paving the road with Jakarta EE and Apache TomEE - JCON 2021
César Hernández
 
PSR7 - interoperabilità HTTP
Massimiliano Arione
 
C/C++ Remote Development Overview
Thitipong Jampajeen
 
Building Command Line Tools with Golang
Takaaki Mizuno
 
plone.api
gilforcada
 
Beyond QA
gilforcada
 
Let the contribution begin
SeongJae Park
 
Best practices for joomla extensions developers
Francesco Abeni
 
用 Go 語言實戰 Push Notification 服務
Bo-Yi Wu
 
Code analysis for a better future
gilforcada
 
Creating an api from design to security.
Roan Brasil Monteiro
 
Pavimentando el camino con Jakarta EE 9 y Apache TomEE
César Hernández
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
Nexus FrontierTech
 

Viewers also liked (20)

PPSX
Php and MySQL
Tiji Thomas
 
PPT
PurpleSearch screenshots
Try PurpleSearch
 
PDF
OE 35 opening of central institution of sanatanis at sanskar dham, Desalpar
Satpanth Dharm
 
PDF
Series 39 1935 Bombay high court case on Satpanth Issue
Satpanth Dharm
 
PDF
Series 30 -Umiya_mataji_unjha_resolution_dt._16-nov-1978
Satpanth Dharm
 
PDF
Series 28 How to counter the threat posed by mavals
Satpanth Dharm
 
PDF
C b-macpherson-the-life-and-times-of-liberal-democracy
University of Campinas
 
PPSX
Series 33 - E - History of Pirana Satpanth Part 2 of 3
Satpanth Dharm
 
PDF
My strategicplan.strategyhuddle.042810
M3Planning
 
PPTX
Likes health project
mschlafly
 
PDF
GE1 important information -on satpanth and samaj d
Satpanth Dharm
 
PPSX
Series 33 - G - PPT - History of Pirana satpanth Part 1 of 3
Satpanth Dharm
 
PPT
Civil society initiatives on engaging peace processes
GenPeace
 
PDF
Series 10 pirana satpanth kaka appointment and admin rights agreement -d
Satpanth Dharm
 
PDF
Series 32 1945 -Umiya Mataji Vandhay Mandir -Inauguration
Satpanth Dharm
 
PPT
Effective googling
Venkatraman Ananthanarayanan
 
PDF
Series 9 attachment -photos of original hindu atharv ved pages
Satpanth Dharm
 
PDF
Anag
GenPeace
 
PPT
Abecedario para niños
informaticadealumnos
 
Php and MySQL
Tiji Thomas
 
PurpleSearch screenshots
Try PurpleSearch
 
OE 35 opening of central institution of sanatanis at sanskar dham, Desalpar
Satpanth Dharm
 
Series 39 1935 Bombay high court case on Satpanth Issue
Satpanth Dharm
 
Series 30 -Umiya_mataji_unjha_resolution_dt._16-nov-1978
Satpanth Dharm
 
Series 28 How to counter the threat posed by mavals
Satpanth Dharm
 
C b-macpherson-the-life-and-times-of-liberal-democracy
University of Campinas
 
Series 33 - E - History of Pirana Satpanth Part 2 of 3
Satpanth Dharm
 
My strategicplan.strategyhuddle.042810
M3Planning
 
Likes health project
mschlafly
 
GE1 important information -on satpanth and samaj d
Satpanth Dharm
 
Series 33 - G - PPT - History of Pirana satpanth Part 1 of 3
Satpanth Dharm
 
Civil society initiatives on engaging peace processes
GenPeace
 
Series 10 pirana satpanth kaka appointment and admin rights agreement -d
Satpanth Dharm
 
Series 32 1945 -Umiya Mataji Vandhay Mandir -Inauguration
Satpanth Dharm
 
Effective googling
Venkatraman Ananthanarayanan
 
Series 9 attachment -photos of original hindu atharv ved pages
Satpanth Dharm
 
Anag
GenPeace
 
Abecedario para niños
informaticadealumnos
 
Ad

Similar to PHP for Android: prototyping Android apps in php (20)

PDF
Unleash your Symfony projects with eZ Platform
Sébastien Morel
 
PDF
NLUUG Spring 2012 - OpenShift Primer
Eric D. Schabell
 
ODP
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
Eric D. Schabell
 
PDF
Hybrid HTML5 Apps
Hugo Rodrigues
 
PPT
Introduction to PHP - SDPHP
Eric Johnson
 
PDF
Building Cross-Platform Mobile Apps
Troy Miles
 
KEY
Android Scripting
Juan Gomez
 
PDF
Php Inside - confoo 2011 - Derick Rethans
Bachkoutou Toutou
 
KEY
Development workflow
Sigsiu.NET
 
PPTX
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi
 
PPTX
All a flutter about Flutter.io
Steven Cooper
 
PPT
State ofappdevelopment
gillygize
 
PDF
OpenShift State of the Union, brought to you by JBoss
Eric D. Schabell
 
PDF
web2py:Web development like a boss
Francisco Ribeiro
 
PDF
Software Quality Assurance Tooling - Wintersession 2024
Henry Schreiner
 
PDF
Apps with Apache Cordova and Phonegap
Christian Grobmeier
 
PDF
MOBILE PENTESTING Frida.pdf
Adityamd4
 
PDF
OpenShift Primer - get your business into the Cloud today!
Eric D. Schabell
 
PDF
Current state-of-php
Richard McIntyre
 
Unleash your Symfony projects with eZ Platform
Sébastien Morel
 
NLUUG Spring 2012 - OpenShift Primer
Eric D. Schabell
 
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
Eric D. Schabell
 
Hybrid HTML5 Apps
Hugo Rodrigues
 
Introduction to PHP - SDPHP
Eric Johnson
 
Building Cross-Platform Mobile Apps
Troy Miles
 
Android Scripting
Juan Gomez
 
Php Inside - confoo 2011 - Derick Rethans
Bachkoutou Toutou
 
Development workflow
Sigsiu.NET
 
Ran Mizrahi - Symfony2 meets Drupal8
Ran Mizrahi
 
All a flutter about Flutter.io
Steven Cooper
 
State ofappdevelopment
gillygize
 
OpenShift State of the Union, brought to you by JBoss
Eric D. Schabell
 
web2py:Web development like a boss
Francisco Ribeiro
 
Software Quality Assurance Tooling - Wintersession 2024
Henry Schreiner
 
Apps with Apache Cordova and Phonegap
Christian Grobmeier
 
MOBILE PENTESTING Frida.pdf
Adityamd4
 
OpenShift Primer - get your business into the Cloud today!
Eric D. Schabell
 
Current state-of-php
Richard McIntyre
 
Ad

PHP for Android: prototyping Android apps in php