I designed an application for android (I used android studio), which actually has an embedded web site, which was made by me in php.
The first screen of the application is a login. I would like to know how I can do to make the system to remember the user name and password, as happens in most of the android applications.
You'll probably gonna need a CookieManager and CookieSyncManager to maintain sessions when making calls in your WebView.
check out the API reference here: http://developer.android.com/reference/android/webkit/CookieSyncManager.html
I think you cannot run a .PHP page on a WebView on android. PHP is server-side so it needs to have a server to interpretate and process .PHP files.
If your goal is to have your android app built with HTTP pages, I suggest you Phonegap / Cordova. Take a look. There are many examples which uses Cache/Built-in storage to store variables.
Related
Without diving deep into programming for iOS and Android, is it possible to wrap a responsive PHP-based webpage in a wrapper that we lock to our url, and present it as our own app?
Also is it possible to make this app remember the users login session and other options (cookies)?
Yes, both Android and iOS support "webviews" (each platform has their own name for it).
In your app, you would simply launch into a webview with the URL that you hard code within the app yourself. Both platform webviews should also support storing cookies too.
Although, since you're wanting something this lightweight, you may want to consider a cross-platform development framework such as React-Native, Cordova/PhoneGap, etc. So that you only have to write the code once and deploy to both iOS and Android.
This probably seems stupid question. But I'm new to ionic apps. I wanted to clear this before development.
Can we build ionic app without API? like we normally do for our website.
Example:
If you go to MySite.com, you will see the site running in php with normal rendering. Would Ionic work same way or it has to go through API Send/Receive request for data handling?
Ionic has no direct requirement on data access. It is built on AngularJS, which is in turn built on Javascript. Best practices would generally have you accessing JSON data from a server by using a mechanism that is Angular aware such as $http, $resource, Restangular, etc.
However, you can execute any javascript based browser command (or even load something like jQuery to perform the data access). However, as soon as you go outside of Angular, then you will have to deal with the additional complexity of making sure the digest cycle is run whenever you have updated values that may be reflected on your view because of data binding.
And, just to be clear, none of this has anything to do with what's happening on the server side. When you are asking about accessing "without API", do you mean accessing HTML files vs. JSON data? Ionic is built to be a SPA (single page application) that is installed on the mobile device and doesn't require internet access to run once it's installed.
Therefore, especially if external/live data isn't required (imagine some type of calculator where you enter values and results can be calculated with just the data in the app on the handset -- without the need for a live server at all), Ionic apps don't REQUIRE access to an external server at all.
You could provide traditional hyperlinks to other html files, but at that point it would no longer be running the packaged/installed files that form the basis of the installed app on the handset and would instead be a web app that is relying on an external server for all views. And, of course, even if it does require access to data from a server, the often massive increase in speed by not round tripping the server with a new HTML page (only a relatively tiny JSON payload in most situations) makes it feel much more like a true native app.
In ionic, the rendering happens on your phone. The server simply provides data. So if you need any data from a server (usually yes) then you need an API.
Ionic is focused on building native/hybrid mobile apps rather than
mobile websites.
– http://ionicframework.com/docs/overview/#browser-support
As per definition, an API only defines the way your ionic app can interact with your php script. In principle, there are no rules on how you design this interaction. So yes, you can keep it quite traditional/old-fashioned. Don't get the concept of an API mixed up with the concepts of RESTful or SOAP APIs etc.
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.
I've developed an android app that interact with my database by using some php scripts (one for each function of my app) that returns a json object with response data.
Now i need to build up a website too that do the same tasks of my app, but i would fix up my server code.
Should i have to maintain my app php scripts separate from website scripts (i'm planning to use some php framework to develop it), or there's a different way to do it?
No! Same script will work for all platforms.
If you follow proper protocols you will be good :)
Use Rest Console or similar tools to test your webservice on browser.
If you are able to get JSON response, then its good for all platform.
If you want to separate out the platforms and devices on server that can be handled by using user agent check at server end.
What is the best way to write an android application that logs into a server? I am thinking I do not want to maintain a socket, so I think I want to avoid that, I think I want to use the http protocol. My question with that is, on the server side, ideally I would like to use PHP to handle the GET/POST calls from the android app, but I don't know how to return (using PHP) information that my app can handle and not just an html file.
So for example, the facebook app for android. When you first download the app, you login and then the app maintains your connection, but obviously the app is not another web browser, but a regular app that presents its information as if it were a web site. How does the app pass the session cookie so that the PHP $_SESSION variables maintain themselves? How does the android app handle the data that comes back?
If I send a get requestion to htt://www.test.php can the PHP code that executes on the server return a custom set of data? Will the $_SESSION variables be automatically maintainted?
Thank you
You can send a get/post request to log on the server. The PHP page can return JSON or XML. Then your Java (Android) code will have to parse that response.
You can have the PHP page log first, and then start a session. Maybe generate a token key and store this in the database, and then return this to the android app. Android app will get this token (after parsing), and probably save it in a preferences file. This approach is basically a custom session. You will have to figure out things like expiration of token, etc.
There might be a way to store PHP sessions, but not sure how an app behaves differently from a browser. I think sessions can be little bit more complicated with apps.
More discussion here: php session destroyed in android application
You just need to create Server Side API which receives and sends data back to Client. Server start session, when API is requested, and Client receives PHPSESSID which is used to keep session opened. On Client, you use cookie for sessions.
Read about sessions: PHP Sessions (simple) and Session Handling (comprehensive)