Python for Android
Within the tools directory, only two programs are of interest to you. The adb utility allows you to transfer files to (and from) your Android emulator (more on this utility later). The android tool lets you prepare and run an emulator for any number of the current Android releases, and that's what you do next:
$ cd Android/tools $ ./android
The android command starts the Android SDK and AVD Manager, which is a tool that creates Android emulators for any number of Android virtual devices. At the moment, there are no virtual devices, so you need to create one. However, before this can happen, you need to install a target Android API package. To do that, click on the Installed Packages tab, then press the Update All button. In the dialog that appears, click Accept All and then press the Install button.
The resulting download takes a while, so drag yourself away from your computer and head off into the kitchen to make a nice cup of coffee. Depending on your download speed, you may have time to make a quick sandwich too.
With the download(s) complete, let's create an Android Virtual Device (AVD). An AVD is a virtual version of an Android device that you can run on the emulator. Select the Virtual Devices tab, then click on the New button. A dialog appears that you can use to set the characteristics of your AVD. Figure 1 shows that I've given my AVD a name (LJapp), selected an API target (API Level 7, which is Android 2.1) and set my virtual SD card to 256 meg. When you have made your selections, click on the Create AVD button to initialize your AVD.
If you return to the Virtual Devices tab, your LJapp AVD now should exist. Select the AVD and press the Start button, then select the Launch button from the displayed dialog. The emulator starts to load, and after a few seconds, you see the opening screen for your emulated Android device (Figure 2). Note that the emulator runs much more slowly than the actual physical phone, so it may take a while to get to the Android startup screen. Your mileage will vary, depending on the speed of your desktop's processor.
Note: throughout the remainder of this article, I use the word “tap” to refer to using the mouse to click within the emulator. There is no mouse pointer on your physical Android device (that's what your finger is for), but the emulator needs something, so the mouse pointer “emulates” your finger, hence the use of the word tap to describe the action required. When you see me use the word tap, think click.
Getting the SL4A on your emulator is straightforward. Start by tapping the Android browser and surfing to the SL4A Web site: code.google.com/p/android-scripting.
When the SL4A Web page appears, tap on the square graphic (the QR Code) to access the download URL for SL4A. The download should begin immediately, and once it completes, tap the downloaded package name (which is sl4a_r3.apk at the time of this writing) to install SL4A. Go ahead and tap on the Install button, then tap on the Open button to start the app. You'll be asked to participate in usage tracking (it's up to you, and it's optional), and then SL4A informs you that you have “No matches found” under your Scripts listing. That's okay; you've yet to install any scripts. SL4A now is ready for Python.
Return to the Android browser and double-tap the screen to enlarge the Web page. Locate the Featured Downloads part of the page on the right, and tap on the download arrow beside the python_for_android_r1.apk link. As before, let the download complete before tapping on the downloaded file to install it. When you're ready, tap the Install button to confirm the installation of the interpreter. When this completes, tap on the Open button, then tap on the big Install button to complete the installation. The Python for Android app downloads, extracts and installs the Python support files from the SL4A Web site and adds them into SL4A. The entire process should take only a minute or two to complete. If it takes longer than a few minutes, take a deep breath, and remember that the emulator is much slower than your physical device.
When the installation completes, you'll be presented with an Uninstall button. Don't tap this button! If you do, you'll remove the Python interpreter that you've just installed. Instead, tap on the emulator's home button (the little house icon) to return to the Android main screen, tap the tab at the bottom of the screen to see the list of installed apps, and note that SL4A has been added to your emulator (Figure 3).
Go ahead and tap the SL4A icon that now displays the list of installed Python scripts. Tapping the hello_world.py script pops up the SL4A run menu (Figure 4). Looking from left to right, the menu icons have the following meaning: 1) run the script at the Python shell, which is useful when debugging; 2) run the script “natively”; 3) edit the script in SL4A's built-in text editor, which is useful only for the most trivial of changes; 4) rename the script; and 5) delete the script. To test your installation quickly, tap the second menu icon, which I like to refer to as the “run wheel”. After a second or two, a message saying “Hello, Android!” appears on screen for a few seconds then disappears.
If that worked, tap the test.py script, then tap the run wheel. This runs a longer-running script that showcases some of the facilities available to you as a Python programmer working on Android. Again, bear in mind that the emulator runs slowly, so be patient and wait for the various Android interface elements to appear.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- My +1 Sword of Productivity
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Non-Linux FOSS: Caffeine!
- Managing Linux Using Puppet
- SuperTuxKart 0.9.2 Released
- Doing for User Space What We Did for Kernel Space
- Google's SwiftShader Released
- Parsing an RSS News Feed with a Bash Script
- Rogue Wave Software's Zend Server
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide