Can PHP be used in Android app development? - php

I've got a book I bought online - O'Reilly's Building Android Apps with HTML, CSS and JavaScript. The idea is that you can use these 3 to create a website that can be converted to an Android app by using a Java conversion tool.
Hopefully someone will be familiar with this, and hopefully this is possible - if I have a website that is already created that also includes PHP, could this be used for the app?
I've created PHP sites before, and the one I'm specifically looking at is referencing a MySQL database, hence my need to use PHP for the app. The website is heavily based on PHP.

No you can't (Unless you created your own framework which runs a local php server inside of the device which can be accessed by a webview). Php is a server side language. Html and JavaScript are client side. These html app creation frameworks use the webview to run apps. Be careful as there are performance issues when running through webview as it is not a native app (projects like crosswalk help but still many issues). Popular frameworks include ionic (Angularjs), titanium (is mostly native but from my experience limiting), and appgyver (Angularjs).

Yes you can! If by "converting" the website to app you mean displaying the website in a chromeless view mode (without address bar).
If you wan't to use phonegap / cordova you can still use the existing PHP code as backend for the database (Maybe rewrite it into a Restful API).
If you want your app to run natively and without internet connection, then you are out of luck though.

Related

Creating an Android app using PHP

I'm going to create an Android app for the first time, and I wanted to do it in PHP, I've done some research and found the likes of PhoneGap, but I'm still quite short in the area, could someone give me a start?
What I'm going to be doing is a simple app for testing, a shop where you search for products, add them to your cart and check out, and the names of the products you ordered will be entered to a database.
Basically;
Search for products->add to cart->check out->info sent to database (all through PHP).
Where should I start?
Cordova is mainly a JavaScript framework that exposes native device features as JavaScript functions. Think of a cordova application like a plain HTML & Javascript website running in a Webview within your mobile application. The PHP interpreter isn't available on a mobile device, which is why you cannot package PHP files into a cordova app and expect it to work.
You could however write your backend in PHP and use XMLHTTP calls (in JavaScript) to retrieve data and present it to the user.
Additionally you can use any JavaScript framework in combination with Cordova so if you are familiar with any of them (like jQuery, Knockout or Angular) that would be an advantage. I'd suggest starting with a Cordova tutorial, like for example this one: https://ccoenraets.github.io/cordova-tutorial/index.html
Another project that is getting alot of attention lately is the Ionic project, which is also based on Cordova. I'd think based on your requirements this would be a great framework to use: http://ionicframework.com/

Is PHP & MySQL allowed in developing android apps?

I would like to make an additional app to my website - is based on PHP & MySQL. Website should be shown in the app. So I would like to ask if PHP & MySQL are allowed in developing android apps? Just to shorten the time spent on programming the app and reduce or skip JS or other languages.
Thanks a lot for answer.
No, that is not possible. You can not build and android app based on php and MySQl. PHP is a server side scripting langauge, while MySQL is a database management System. What you can is that you can provide APIs which may be used by your mobile application to get and post data.
"Allowed"?
Well Android runs third party applications using Java. You can run more languages using the Android NDK, but the PHP+MySQL is not supposed to work on Android as it does on lets say Apache...
It's Android: a Java-based OS.
And I doubt you'll save time like that.
Make your website mobile-ready or build a regular Android (so Java) application is my adice.

Opencart and phonegap

Hi I have recently began to build mobile open cart sites for mobile browsers. I would like to take it a step further and build native apps using phonegap. My question is , does phonegap support a structure like opencart? Are php files supported?
Would it be possible for me to build a fully functioning opencart site and integrate it successfully with phonegap?
There is very little information online regarding this question.
A Phonegap app cannot contain any server side scripting like PHP. It can only contains HTML, css and Javascript.
But you can always do request to a remote server that runs PHP.
Opencart has quite a few ajax interfaces in various parts of the app. These call controllers that deliver sections of a page usually. I have not looked into the full remote API to know if you can build a full shop app that uses the opencart backend.
If you look down that ajax calls path you may find enough functionality to produce the phonegap app.

Moving php apps to Android and iPhone

I am a php developer with a few web apps like a project management app and a forum i'd like to move to Android and iPhone.
I've heard of developers using Sencha Touch and PhoneGap to develop native apps and I know they support HTML5, CSS and Javascript, but how abot PHP? And is are there any other APIs/frameworks I should consider that better support local server scripting?
Speaking about webapp, maybe you can avoid building an app by having a mobile enabled version of your website compliant with all the client browsers.
Have a look at jquerymobile, it is compliant with mostly all the mobile browsers and you will be able to reuse your code.
To answer correctly, you can call your webservices using ajax to fetch json/xml/etc data from Phonegap because it is using jQuerymobile ;-)
Have a look at this discussion here on Stackoverflow :
Passing formdata from Phonegap to PHP with JSON
Hope this helps
PHP is a server-side scripting language and your .php files have to be stored on the server side. You can access them asynchronously with Ajax, so no, you can not include php files (with reasonable time and effort) in your app.
The only smart way to go here is native iOS apps, forget PHP, Android and the rest of that crap. By the way I'm not trying to be an iOS snob here but am just reflecting on a few realities. One is that iOS apps can actually make money though a web replacement app might not. The second issue is that going native demands a reboot on your part, that is best done on one platform until you get up to speed. The third issue is that users now a days expect well performing apps that don't have a lot of web cruft in them. Fourth the Android marketplace is screwed, you are far more likely to establish that critical user base on iOS as you can target a handful of platforms running the latest generation of iOS, android is by comparison a pathetic mess of old versions of android running on all sorts of hardware.
On iOS look a BlueAlien as an example of a better than web method of accessing Reddit.

I want to create a mobile website in addition to native apps using phonegap. Is it sensible to use the same codebase?

I want to have a mobile-friendly website, in addition to a native app for iphone/android using phonegap. I'm currently using PHP (specifically CodeIgniter but that's not as important) and jQuery for the mobile website.
I'm thinking that the website and the phonegap codebase can use the same PHP back-end for server requests but the front-end must be somewhat different since phonegap has proprietary javascript to access native functionality (camera, accelerometer, etc) that a browser couldn't access. For this reason, I think the front-end must be developed separately for the mobile site vs. for phonegap.
Does this make sense? Am I missing something that would allow me to use the same phonegap codebase as the mobile site?
Where I work, we developed our mobile website and Android App with the same codebase except for the views and UI. Everything on the web side is in pure JS and HTML. We have a sever side API that we request data from and then template it using Mustache.
We used Titanium for the Android App, but found that framework to have more cons than pros to use. So for the iPhone app upgrade we're using PhoneGap. It took us a few hours but the mobile site ported over exactly the way it works in browser, to the native iPhone app created by PhoneGap. In short, It's absolutely possible but you have to develop the site in JS, all the logic, to have it port over easily to PhoneGap.
Also, just a recommendation, you should try using Zepto.js instead of jQuery. It's aerogel weight, has the majority of jQuery functionality without all the IE bull and it uses the familiar $ symbol as a namespace. Much more suitable for mobile development.
Specifically, PhoneGap has plugins that you write. There's two sides to this, one JS file which will match the plugin that you write for the native Obj C or Android file. The plugins are modular, so you can plug them in for the native apps and out for the site.

Categories