Web Server Product
The main component of the offline application cache is a cache manifest file that you host on your web server. I'm going to use a simple example to explain the concepts involved, then I'll show you how to apply what you've learned to the Kilo example we've been working on. A manifest file is just a simple text document that lives on your web server and is sent to the user's device with a content type of cache-manifest. The manifest contains a list of files a user's device must download and save in order to function. Consider a web directory containing the following files You must serve the manifest file with the text cache-manifest content type or the browser will not recognize it. If you are using the Apache web server or a compatible web server, you can accomplish this by adding an .htaccess file to your web directory with the following line If the .htaccess file doesn't work for you, please refer to the portion of your web server documentation that pertains to MIME types. You must...
Once you have signed your application with a private key, you can install it on an emulator or device as discussed in the following section about Running Your Application. You can also try installing it onto a device from a web server. Simply upload the signed APK to a web site, then load the .apk URL in your Android web browser to download the application and begin installation. (On your device, be sure you have enabled Settings Applications Unknown sources.)
Fortunately, security between clients and servers on the World Wide Web is mainly handled through public key encryption. This encryption method is a built-in feature of most web servers and clients, including Android. As a programmer, you need not concern yourself with public key encryption, other
The Create button, a request is made to a lightweight embedded web server in Rhodes that only exists to respond to these UI request and RhoController actions. When a user clicks on a URL in the HTML view, a controller action is called. In this example, the ProductController create method is called. The controller action then calls the Product model, implemented with Rhom to save a new product in the local database. Then a view is rendered to display the result to the user. The entire web response cycle happens locally on the device.
Running PHP Scripts on Your Web Server PHP is a versatile web-scripting language, and is supported by most web hosting providers. This means that on most web servers, you can create a file whose name ends with the extension .php, add some PHP code to it, visit it in your web browser, and it will just work. If you've been using a web server on your personal computer to serve up pages to your Android phone, you'll need to get set up to run PHP scripts. If you're running a web server on Windows, see for downloads and information. You may also want to use a solution such as EasyPHP or check out the Wikipedia page on this topic at http en.wikipedia.org wiki Comparison_of_WAMPs. 6. Clear the checkbox next to Web Sharing and then check it again. Now PHP should be enabled on your Mac's web server. As I mentioned earlier in this chapter, the first line of a cache manifest file must be CACHE MANIFEST. As far as the browser is concerned, this is the first line of the document the PHP file runs...
Note that you can also set this value to access sites hosted on external web servers by entering the full URL with the http prefix. However, before you can access external sites from the emulator, you must ensure that you have cradled the emulated device. To connect to an emulator, select Device Emulator Manager from the Tools menu, select the emulator name from the list, and click Actions Connect. A green arrow will be displayed beside the emulator when it is running. To cradle the emulator, select its name once again, select Actions Cradle, and go through the motions with the ActionSync dialogues that are displayed.
The only thing stopping us from running this example application in offline mode is that we have to initially connect to the web server each time the app is launched to download the HTML and related resources. Wouldn't it be schweet if we could just cache all that stuff locally on the device Yeah, it would.
If you want to see what's happening from the web server's perspective, you can monitor its log files. For example, if you are running a web ' ' 1.4' server on a Mac or Linux computer, you can open the command line (see Using the Command Line on page 110), and run these commands (the is the shell prompt, which you should not type) This will display the web server's log entries, showing information such as the date and time a document was accessed, as well as the name of the document. When you are done, press Control-C to stop following the log.
Create a cache directory and make sure it's writable by whichever user runs PHP scripts. If your web server is configured to run your PHP scripts under your user credentials, this step should not be necessary. As with previous examples, replace src wurfl-php-1.1 with the location you created earlier. Replace _www with the username that your PHP scripts run under (you will need superuser credentials to run this command)
Many different types of web servers service browser requests, so the principles presented in this chapter are generic instead of tailored to specific web servers. Each type has its own way of doing things, and it is beyond the scope of this book to give specific instructions for each web server type. Suffice it to say that the modern web server provides different programmatic methods for reading the user-agent string (and all the other strings shown in the browser request), and code that parses, examines, and reacts to the content of those strings depends on the specific server the webmaster is using. The specific web server's documentation includes detailed information. Having said that, this chapter focuses on what to do instead of how to do it, based on the user-agent string. For example, if the server determines that an Android-powered handset is requesting a web page, it should return a smaller, less dense HTML page. When designing web content to be rendered on small machines,...
If you just need SSL (Secure Socket Layer) for connecting to a web server for file management, you can use ConnectBot. SSL is an Internet standard protocol for transferring information. It's commonly used for transferring files. ConnectBot is available in the Android Market.
To add a connection to your Product model, change the title Add links here to Products and href to Product as shown in Listing 6-6. This will create a link to the Product model's index page app Product index.erb-just with most web servers, the default page for a URL is index and the relative URL will look for a sibling page to index.erb that is also in the app folder. Note that most of the page is pure HTML and you could put other links here or add graphics with an tag or add text. The part of the page that is embedded Ruby code is inside .