This document discusses bringing PHP scripting capabilities to Android devices. It describes how PHP can be compiled to run on Android using the Scripting Layer for Android (SL4A) project. SL4A exposes the Android API to scripting languages and has added support for PHP through the PHP for Android project. This allows PHP scripts to access Android features like location services, sending emails, and interacting with the mobile OS. An example PHP script is provided that uses location data to generate a Google Maps link and email the user's current location.
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. 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. PHP for Android: scripting PHP en Android
The problem
● API php → OK
● UI? (php-gtk?)
● Calls?
● Messages?
● Location?
● Sensors?
● ...
● Mobile web.
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.
16. PHP for Android: scripting PHP en Android
SL4A
● Script management.
● Android Facades.
● Interpreter install.
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. 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. 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. 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. PHP for Android: scripting PHP en Android
The Android class
<?php
require “Android.php”;
$droid = new Android();
$droid->viewContacts();
22. PHP for Android: scripting PHP en Android
“WhereAmI” script
● Location.
● Email building (google maps link).
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. PHP for Android: scripting PHP en Android
PFAf
start
locate
credicts
info
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. PHP for Android: scripting PHP en Android
Script sharing
● SL4A scripts folder.
● Barcode (<4296 chars)
● Script on APK:
– Template project → customize.
– ANT
30. PHP for Android: scripting PHP en Android
Roadmap
● SL4A
– API extended.
● GUI...
– Bugfixes.
● PFA
– Sqlite,... phpize.
– supporting SL4A releases.
31. PHP for Android: scripting PHP en Android
?????
Questions
Logo @Workoholics_