TODO Create a script file repo in phpforandroid.net/scripts
<?php require_once("Android.php"); $droid = new Android(); $name = $droid->getInput("Hi!", "What is your name?"); $droid->makeToast('Hello, ' . $name['result']);
<?php require_once("Android.php"); $droid = new Android(); $droid->vibrate();
<?php require_once("Android.php"); phpinfo();
<?php require_once("Android.php"); $droid = new Android(); $droid->dialogCreateAlert(); $droid->dialogSetItems(range(0, 9)); $droid->dialogShow();
<?php require_once("Android.php"); $droid = new Android(); //include("http://YOURHOST/yourfile.php.txt");
getLocation1.php: gets location info by the given latitude and longitude. <?php // @author: Anton Perkin (anton.perkinAT_NOSP_AMgmail.com) // http://groups.google.com/group/php-for-android/browse_thread/thread/bab685d3ae202152 include("Android.php"); $droid = new Android(); //creates alert $droid->dialogCreateAlert(); $result = array(); //gets coordinates $latitude = $droid->getInput("Location", "Latitude: "); $longitude= $droid->getInput("Location", "Longitude: "); //gets the location info $locations = $droid->geocode($latitude['result'], $longitude['result']); //parses location info foreach ($locations['result'] as $location) { $location = get_object_vars($location); //sets location items foreach ($location as $key => $value) { $result[] = ucfirst(str_replace('_', ' ', $key)).': '.$value; } } $droid->dialogSetItems($result); //displays the box $droid->dialogShow();
horoscope.php: Proof of Concept retrieving horoscope information <?php // @author: Javier Infante <jabiAT_NOSP_AMirontec.com> require_once("Android.php"); $droid = new Android(); $action = "start"; while (true) { switch($action) { case "start": $droid->dialogCreateAlert("PFA-Horoscope","Ask PFAewok for your Horoscope"); $droid->dialogSetPositiveButtonText("ask now!"); $droid->dialogSetNegativeButtonText("credits..."); $droid->dialogShow(); // Wait for user input $result = $droid->dialogGetResponse(); switch ($result['result']->which) { case "negative": $action = "credits"; break; case "positive": default: $action = "choose_and_ask"; break; } $droid->dialogDismiss(); break; case "credits": $droid->dialogCreateAlert("PFA-Horoscope","Only for educational Purpouses (what else?).\n\nHoroscope Source: http://widgets.fabulously40.com/horoscope.json\n\nwww.phpforandroid.net"); $droid->dialogSetPositiveButtonText("back"); $droid->dialogSetNegativeButtonText("exit"); $droid->dialogShow(); // Wait for user input $result = $droid->dialogGetResponse(); switch ($result['result']->which) { case "negative": $action = "bye"; break; case "positive": default: $action = "start"; break; } $droid->dialogDismiss(); break; case "choose_and_ask": $droid->dialogCreateAlert("Choose your sign:"); $zodiac = array("aries","taurus","gemini","cancer","leo","virgo","libra","scorpio","sagittarius","capricorn","aquarius","pisces"); $droid->dialogSetItems($zodiac); $droid->dialogShow(); $result = $droid->dialogGetResponse(); $url = "http://widgets.fabulously40.com/horoscope.json?sign=".$zodiac[$result['result']->item]; // Downloading the horoscope might take a while... $droid->dialogCreateSpinnerProgress("Retrieving information...","Please wait"); $droid->dialogShow(); // Downloading and de-json-ing $result = json_decode(file_get_contents($url)); // we are ready! $droid->vibrate(); // Close spinner $droid->dialogDismiss(); $theFuture = html_entity_decode($result->horoscope->horoscope,ENT_QUOTES,"UTF-8"); // Something is wrong with '... $theFuture = str_replace("'","'",$theFuture); $theFuture .= "\n\n[widgets.fabulously40.com]"; $droid->dialogCreateAlert("Your Future is here ".$result->horoscope->sign . "!",$theFuture); $droid->dialogSetPositiveButtonText("Exit"); $droid->dialogShow(); // Wait for user input to continue script $droid->dialogGetResponse(); $action = "bye"; break; case "bye": $droid->makeToast("Trust the PFAewok!"); $droid->exit(); exit(); break; } // Main switch } // main while // EOF
<?php // @author: Gorka Gorrotxategi <zgor@irontec.com> // Thanks Ktulur!!! /* Initial Stup for PFA Fun!*/ require_once("Android.php"); $droid = new Android(); /* Some GUI for the user */ $droid->dialogCreateAlert("AstMofix","Ready to connect to your Asterisk powered BOX and get simple event stats"); $droid->dialogSetNeutralButtonText("I'm Ready to fun!"); $droid->dialogShow(); $result = $droid->dialogGetResponse(); /* Get parameters */ /* 1- Remote AMI server */ $server=$droid->getInput("Please enter IP/Hostname of your Asterisk BOX",""); /* 2- Remote AMI port */ $port=$droid->getInput("Please enter TCP Port",""); /* 3- Remote user */ $user=$droid->getInput("Please enter username",""); /* 4- Remote pass */ $pass=$droid->getPassword("Please enter password",""); $server=$server['result']; $port=$port['result']; $user=$user['result']; $pass=$pass['result']; echo "Ready to connect to $server:$port with $user/$pass\n"; /* TCP Connection */ $astSocket = fsockopen($server, $port, $errno, $errstr, 30); if (!$astSocket) { $droid->dialogCreateAlert("AstMofix","Sorry, TCP Connection on $server : $port was not possible :r("); $droid->dialogSetNeutralButtonText("I will try again :D)"); $droid->dialogShow(); $result = $droid->dialogGetResponse(); exit(1); } /* Authentication process ... */ $droid->dialogCreateSpinnerProgress("Connection Successfull!!!\nNow: Trying to Authenticate","Please wait"); $droid->dialogShow(); $login = "Action: Login\r\n"; $login .= "Username: $user\r\n"; $login .= "Secret: $pass\r\n\r\n"; echo "Sending:\r\n $login \r\n"; fwrite($astSocket,$login); $response=fgets($astSocket); // "Asterisk Call Manager..." $response=fgets($astSocket); // "Response: Success..." if (strpos($response,"Success") == false) { $droid->dialogDismiss(); $droid->dialogCreateAlert("AstMofix","Sorry, AMI Auth Failed $server : $port with $user/$pass \n"); $droid->dialogSetNeutralButtonText("I will try again :D)"); $droid->dialogShow(); $result = $droid->dialogGetResponse(); exit(1); } $droid->dialogDismiss(); $droid->dialogCreateSpinnerProgress("Auth Sucessfull !!! Ready to play ;)","Fetching some initial info, please wait"); $droid->dialogShow(); sleep(10); $droid->dialogDismiss(); $eventsArray=array(); $timetorefresh=time(); /* MAIN BIG LOOP */ while (1) { // Receive ... $line = fgets($astSocket); //echo ">> $line"; if (substr($line,0,5) == "Event") { $parts = explode(":",$line); $event=$parts[1]; $eventsArray["$event"]=$eventsArray["$event"]+1; } $lastupdate=time()-$timetorefresh; if ( $lastupdate > 15) { $values=var_dump($eventsArray); $droid->dialogDismiss(); $droid->dialogCreateSpinnerProgress("Updated info",$values); $droid->dialogShow(); $lastupdate=time(); } }