Categories: general

Fetching Android Repo With PHP

Now we will learn how to fetch values from android repository with PHP, and display it on your page. (See andiim3.com for example).

Usually, android user will use aptoide, APKtor, etc. to browse outside repo beside Google’s Android Market. But, there a lot of user prefer to download the apps from PC browser instead of their mobile.

We need to know that every android repo provide us a XML file to read. Named info.xml, it contains all the information needed by the client. So, we will fetch the info.xml.

I will explain the steps inline with the code. Remember, this is the basic script I use in alpha version of my website (andiim3.com). andiim3.com now use more advanced way to fetch the repos, but the basic method still included.

// specify the repo URL below:
$repo="http://aptoide.com/repo/";
$repodir=$repo; // we need it later as the basepath

// Then, by using simplexml_load_file() function, we fetch the info.xml.
$repo=$repo."info.xml";
$xml = simplexml_load_file($repo);
$tracks = $xml->package;

//now we have all the value in one array variable, $tracks
// now we will extract the values

$number = 50;
// that was estimation number of the apk listed inside the info.xml,
//I use 5000 for a big repo 

for ($i = 0; $i < $number; $i++) {
    $package = $tracks[$i];

     // the name of the apps
          $name = $package->name;    
    // the path
          $url = $package->path; 
    // this is the full path
          $url=$repodir.$url; 
    // apk version
          $ver = $package->ver;   
    // prevent if the version is empty
          if($ver!=""){$ver="$ver";} else {$ver="Unknown";} 
    // date of apk insertion to the xml 
          $date = $package->date;  
          if($date!=""){$date="$date";} else {$date=date("Y-m-d");}
    // the package’s icon
          $img = $package->icon;
          if($img!=""){$img=$repodir.$img;}
    // package ID, we need it, trust me.. 😀
    // (I use it in andiim3.com for details fetching)
          $id = $package->apkid;
          if($id==""){$id="Unknown";}

    // now you can output the package details as you want..
    // output in table format is the best, but you may try different method
    echo “<img src=’$img’ style=’float:left;’ width=’48’ />”;
    echo “Name : $name <br/>”;
    echo “Version : $ver <br/>”;
    echo “Date : $date<br/>”;
    echo “APK ID : $apkid <br/>”;
    echo “<a href=’$url’>Download</a> <br/><br/>”;

    }

 

That’s it.. You may use this script in your own website. But I warn you, this method can waste your web hosting bandwidth if you don’t have an unlimited hosting plan.

As usually, I will give you the algorithm of my advanced script used in andiim3.com

  1. To save the bandwidth, we fetch the info.xml once a day, we use cron in cpanel
  2. In fetching process: first, we truncate the database before inserting new data to prevent duplicate rows. Then we insert all the new apk data back to the database.
  3. We don’t output the apk data in the cron job, it is unnecessary. We use another script to display the database to the audience. I think it’s quite easy to fetch the rows from database and display it on your pages. Code it yourself!

The advantages of using database is to save your bandwidth, saves times (no need to fetch all the repos first for one only request), we can do easy APK searching, we can short it, we can track the statistic, etc.

Andi Setiawan

Loving husband - Caring Father - Slap bet Commissionaire (I wish) find my complete profile on: http://andisetiawan.com/about-me http://facebook.com/andiim3 - http://gplus.to/andiim3 - http://andiim3.com

Share
Published by
Andi Setiawan

Recent Posts

Dedicated Blog for Dobby and Luna

Dobby and Luna have been part of our lives for the past years. They have…

2 years ago

Demo Site For My Projects

In the year 2021, I've completed some paid projects. Some of them are more technical,…

2 years ago

GlassTime – Glassmorphism WordPress Theme

Based on the GlassTime Bootstrap template, here I present glassmorphism WordPress Theme free to download.This…

3 years ago

GlassTime : Glassmorphism Responsive HTML5 Template

This HTML5 template is using Glassmorphism UI design language which is now trending for 2021…

3 years ago

Daftar Desa, Kecamatan, dan Kode Pos Buleleng – Bali

KecamatanKode POSBanjar81152Buleleng81119Busungbiu81154Gerokgak81155Kubutambahan81172Sawan81171Seririt81153Sukasada81161Tejakula81173Klik pada nama kecamatan untuk melihat daftar desa masing-masing. Sumber: kodepos.andiim3.com

3 years ago

Ninja diganti ADV

Ada yang bilang "semuanya akan mati matic pada akhirnya". Bener aja, sekarang tuntutan transportasi sehari-hari…

4 years ago

This website uses cookies.