This is a discussion on Android Tips and tricks within the Mobile Software Development forums, part of the Software Development category; installing Andriod sdk Google recently launched their new mobile SDK – Android. Included with the SDK is a mobile device emulator ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| installing Andriod sdk Google recently launched their new mobile SDK – Android. Included with the SDK is a mobile device emulator that allows developers to see what their application look and feel like on Android.Android is a software stack for mobile devices that includes an operating system, middleware and key applications. here the following link for android sdk Download the Android SDK - Android
__________________ cheers Aman |
| Sponsored Links |
| |||
| Features in Andriod followings are the features of andriod * Application framework enabling reuse and replacement of components * Dalvik virtual machine optimized for mobile devices * Integrated browser based on the open source WebKit engine * Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional) * SQLite for structured data storage * Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF) * GSM Telephony (hardware dependent) * Bluetooth, EDGE, 3G, and WiFi (hardware dependent) * Camera, GPS, compass, and accelerometer (hardware dependent) * Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE
__________________ cheers Aman |
| |||
| Android in eclipse following are the steps to integrate andriod in eclipse: 1)Inorder to integrate you need to create a new MCS project (or use an existing MCS project) and import into the project a copy of the devices.mdpr file into the project using the standard Eclipse file import wizard. 2) open up devices.mdpr file (the default editor within an MCS project will automatically open the file for editing within the Device Repository Editor). 3)Using the editor within the Overview tab select “Mobile” in the device hierarchy (or some other device beneath Mobile to your liking) and select “New” add a new device e.g. Android_Default. 4)add a Primary Pattern for your new device be clicking “Add” by the Primary Patterns text area. A primary pattern is a regular expression that should match the user-agent header of the associated device. 5)The user-agent for the default device emulator in Android is: PHP Code: PHP Code: 7)save your changes and that should be enough to get started developing policies for Android and allowing VMS to recognize the Android default emulator when it receives a request from one. Feel free to add more policy values as required. At some point in the future VMS may come with built-in support for Android and when this happens the policy values are likely to be much more comprehensive.
__________________ cheers Aman |
| |||
| Installing the Eclipse Plugin (ADT) Android Development Tools (ADT), which adds integrated support for Android projects and tools. The ADT plugin includes a variety of powerful extensions that make creating, running, and debugging Android applications faster and easier. If you will not be using the Eclipse IDE, you do not need to download or install the ADT plugin. To download and install the ADT plugin, follow the steps below. 1. Start Eclipse, then select Help > Software Updates > Find and Install.... 2. In the dialog that appears, select Search for new features to install and press Next. 3. Press New Remote Site. 4. In the resulting dialog box, enter a name for the remote site (e.g. Android Plugin) and enter this as its URL: https://dl-ssl.google.com/android/eclipse/ Press OK. 5. You should now see the new site added to the search list (and checked). Press Finish. 6. In the subsequent Search Results dialog box, select the checkbox for Android Plugin > Developer Tools. This will check both features: "Android Developer Tools", and "Android Editors". The Android Editors feature is optional, but recommended. If you choose to install it, you need the WST plugin mentioned earlier in this page. Now press Next. 7. Read the license agreement and then select Accept terms of the license agreement, if appropriate. Press Next. 8. Press Finish. 9. The ADT plugin is not signed; you can accept the installation anyway by pressing Install All. 10. Restart Eclipse. 11. After restart, update your Eclipse preferences to point to the SDK directory: 1. Select Window > Preferences... to open the Preferences panel. (Mac OS X: Eclipse > Preferences) 2. Select Android from the left panel. 3. For the SDK Location in the main panel, press Browse... and locate the SDK directory. 4. Press Apply, then OK.
__________________ cheers Aman |
| |||
| Updating the ADT Plugin In some cases, a new ADT plugin may become available for your existing version of the SDK. You can use the steps below to update the ADT plugin from inside Eclipse. 1. Select Help > Software Updates > Find and Install.... 2. Select Search for updates of the currently installed features and press Finish. 3. If any update for ADT is available, select and install. Alternatively, 1. Select Help > Software Updates > Manage Configuration. 2. Navigate down the tree and select Android Development Tools <version> 3. Select Scan for Updates under Available Tasks.
__________________ cheers Aman |
| |||
| Creating an Android Project The ADT plugin provides a New Project Wizard that you can use to quickly create an Eclipse project for new or existing code. To create the project, follow these steps: 1. Select File > New > Project 2. Select Android > Android Project, and press Next 3. Select the contents for the project: * Select Create new project in workspace to start a project for new code. Enter the project name, the base package name, the name of a single Activity class to create as a stub .java file, and a name to use for your application. * Select Create project from existing source to start a project from existing code. Use this option if you want to build and run any of the sample applications included with the SDK. The sample applications are located in the samples/ directory in the SDK. Browse to the directory containing the existing source code and click OK. If the directory contains a valid Android manifest file, the ADT plugin fills in the package, activity, and application names for you. 4. Press Finish. The ADT plugin creates the these folders and files for you as appropriate for the type of project: * src/ A folder that includes your stub .java Activity file. * res/ A folder for your resources. * AndroidManifest.xml The manifest for your project.
__________________ cheers Aman |
| |||
| Creating a Launch Configuration Before you can run and debug your application in Eclipse, you must create a launch configuration for it. A launch configuration specifies the project to launch, the Activity to start, the emulator options to use, and so on. To create a launch configuration for the application, follow these steps: 1. Select Run > Open Run Dialog... or Run > Open Debug Dialog... as appropriate. 2. In the project type list on the left, right-click Android Application and select New. 3. Enter a name for your configuration. 4. On the Android tab, browse for the project and Activity to start. 5. On the Target tab, set the desired screen and network properties, as well as any other emulator startup options. 6. You can set additional options on the Common tab as desired. 7. Press Apply to save the launch configuration, or press Run or Debug (as appropriate).
__________________ cheers Aman |
| |||
| Run and Debug Application Once you've set up the project and launch configuration for your application, you can run or debug it as described below. From the Eclipse main menu, select Run > Run or Run > Debug as appropriate, to run or debug the active launch configuration. Note that the active launch configuration is the one most recently selected in the Run configuration manager. It does not necessarily correspond to the application that is selected in the Eclipse Navigation pane (if any). To set or change the active launch configuration, use the Run configuration manager, which you can access through Run > Open Run Dialog... or Run > Open Debug Dialog.... Running or debugging the application triggers these actions: * Starts the emulator, if it is not already running. * Compiles the project, if there have been changes since the last build, and installs the application on the emulator. * Run starts the application. * Debug starts the application in "Wait for debugger" mode, then opens the Debug perspective and attaches the Eclipse Java debugger to the application.
__________________ cheers Aman |
| |||
| Executing arbitrary Java expressions in Eclipse You can execute arbitrary code when paused at a breakpoint in Eclipse. For example, when in a function with a String argument called "zip", you can get information about packages and call class methods. You can also invoke arbitrary static methods: for example, entering android.os.Debug.startMethodTracing() will start dmTrace. Open a code execution window, select Window>Show View>Display from the main menu to open the Display window, a simple text editor. Type your expression, highlight the text, and click the 'J' icon (or CTRL + SHIFT + D) to run your code. The code runs in the context of the selected thread, which must be stopped at a breakpoint or single-step point. (If you suspend the thread manually, you have to single-step once; this doesn't work if the thread is in Object.wait().) If you are currently paused on a breakpoint, you can simply highlight and execute a piece of source code by pressing CTRL + SHIFT + D. You can highlight a block of text within the same scope by pressing ALT +SHIFT + UP ARROW to select larger and larger enclosing blocks, or DOWN ARROW to select smaller blocks. Here are a few sample inputs and responses in Eclipse using the Display window. Input Response zip (java.lang.String) /work/device/out/linux-x86-debug/android/app/android_sdk.zip zip.endsWith(".zip") (boolean) true zip.endsWith(".jar") (boolean) false You can also execute arbitrary code when not debugging by using a scrapbook page. Search the Eclipse documentation for "scrapbook". Running DDMS Manually Although the recommended way to debug is to use the ADT plugin, you can manually run DDMS and configure Eclipse to debug on port 8700. (Note: Be sure that you have first started DDMS).
__________________ cheers Aman |
| |||
| Debug and Test Settings on the Device Android lets you set a number of settings that will make it easier to test and debug your applications. To get to the development settings page on the emulator, go to Dev Tools > Development Settings. This will open the development settings page with the following options (among others): * Debug app Selects the application that will be debugged. You do not need to set this to attach a debugger, but setting this value has two effects: o It will prevent Android from throwing an error if you pause on a breakpoint for a long time while debugging. o It will enable you to select the Wait for Debugger option to pause application startup until your debugger attaches (described next). * Wait for debugger Blocks the selected application from loading until a debugger attaches. This way you can set a breakpoint in onCreate(), which is important to debug the startup process of an Activity. When you change this option, any currently running instances of the selected application will be killed. In order to check this box, you must have selected a debug application as described in the previous option. You can do the same thing by adding waitForDebugger() to your code. * Immediately destroy activities Tells the system to destroy an activity as soon as it is stopped (as if Android had to reclaim memory). This is very useful for testing the onFreeze(Bundle) / onCreate(android.os.Bundle) code path, which would otherwise be difficult to force. Choosing this option will probably reveal a number of problems in your application due to not saving state. * Show screen updates Flashes a momentary pink rectangle on any screen sections that are being redrawn. This is very useful for discovering unnecessary screen drawing. * Show CPU usage Displays CPU meters at the top of the screen, showing how much the CPU is being used. The top red bar shows overall CPU usage, and the green bar underneath it shows the CPU time spent in compositing the screen. Note: You cannot turn this feature off once it is on, without restarting the emulator. * Show background Displays a background pattern when no activity screens are visible. This typically does not happen, but can happen during debugging. These settings will be remembered across emulator restarts.
__________________ cheers Aman |
| |||
| Storing, Retrieving and Exposing Data A typical desktop operating system provides a common file system that any application can use to store and read files that can be read by other applications (perhaps with some access control settings). Android uses a different system: on Android, all application data (including files) are private to that application. However, Android also provides a standard way for an application to expose its private data to other applications. This section describes the many ways that an application can store and retrieve data, expose its data to other applications, and also how you can request data from other applications that expose their data. Android provides the following mechanisms for storing and retrieving data: Preferences: A lightweight mechanism to store and retrieve key/value pairs of primitive data types. This is typically used to store application preferences. Files: You can store your files on the device or on a removable storage medium. By default, other applications cannot access these files. Databases The Android APIs contain support for SQLite. Your application can create and use a private SQLite database. Each database is private to the package that creates it. Content Providers: A content provider is a optional component of an application that exposes read/write access to an application's private data, subject to whatever restrictions it wants to impose. Content providers implement a standard request syntax for data, and a standard access mechanism for the returned data. Android supplies a number of content providers for standard data types, such as personal contacts. Network: Don't forget that you can also use the network to store and retrieve data.
__________________ cheers Aman |
| |||
| Using Application Preferences You can store application preferences such as a default greeting or text font to be loaded whenever this application is started. Call Context.getSharedPreferences() to read and write values. Assign a name to your set of preferences if you want to share them with other components in the same package, or use Activity.getPreferences() with no name to keep them private to the calling activity. You cannot share preferences across packages. Here is an example of setting user preferences for silent keypress mode for a calculator. Code: public class Calc extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
...
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
...
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);
setSilent(silent);
}
@Override
protected void onStop(){
super.onStop();
// Save user preferences. We need an Editor object to
// make changes. All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);
// Don't forget to commit your edits!!!
editor.commit();
}
}
__________________ cheers Aman |
| |||
| Using Files Android provides access to read or write streams to files local to an application. Call Context.openFileOutput() and Context.openFileInput() with a local name and path to read and write files. Calling these methods with the same name and path strings from another application will not work; you can only access local files. If you have static files to package with your application at compile time, you can save your file in your project in res/raw/<mydatafile>, and then get it with Resources.openRawResource (R.raw.mydatafile).
__________________ cheers Aman |
| |||
| Using SQLite Databases Android supports a SQLite database system and exposes database management functions that let you store complex collections of data wrapped into useful objects. For example, Android defines a Contact data type that consists of many fields including string first and last names, string address and phone numbers, a bitmap image, and much other information describing the person. To create a database, use Context.createDatabase() and Context.openDatabase(), and read and write this data as appropriate. (Note that file data such as a bitmap is typically stored as a string file path value in the database, with the location of the local file.) Android ships with the sqlite3 database tool, which enables you to browse table contents, run SQL commands, and perform other useful functions on SQLite databases. See Examine databases (sqlite3) to learn how to run this program. All databases, SQLite and others, are stored on the device in /data/data/<package_name>/databases Discussion of how many tables to create, what fields they contain, and how they are linked, is beyond the scope of this document, but Android does not impose any limitations beyond the standard SQLite concepts. We do recommend including an autoincrement value key field that can be used as a unique ID to quickly find a record. This is not required for private data, but if you implement a content provider, you must include such a unique ID field. See the sample class NotePadProvider.java in the NotePad sample project for an example of creating and populating a new database. Any databases you create will be accessible by name to any other class in the application, but not outside the application.
__________________ cheers Aman |
| |||
| Accessing Content Providers If you want to make your data public, you can create (or call) a content provider. This is an object that can store and retrieve data accessible by all applications. This is the only way to share data across packages; there is no common storage area that all packages can share. Android ships with a number of content providers for common data types (audio, video, images, personal contact information, and so on). You can see some of Android's native content providers in the provider package. How a content provider actually stores its data under the covers is up to the implementation of the content provider, but all content providers must implement a common convention to query for data, and a common convention to return results. However, a content provider can implement custom helper functions to make data storage/retrieval simpler for the specific data that it exposes. This document covers two topics related to Content Providers: * Using a Content Provider * Creating a Content Provider
__________________ cheers Aman |
| |||
| Modifying Data To update an individual record, set the Cursor to the appropriate object, call the appropriate update... method, and then call commitUpdates(). To batch update a group of records (for example, to change "NY" to "New York" in all contact fields), call the ContentResolver.update() method with the columns and values to change. Remember, whenever calling updating methods on the Cursor class, you must call commitUpdates() to send the changes to the database.
__________________ cheers Aman |
| |||
| Adding a New Record To add a new record, call ContentResolver.insert() with the URI of the type of item to add, and a Map of any values you want to set immediately on the new record. This will return the full URI of the new record, including record number, which you can then use to query and get a Cursor over the new record. Remember, whenever calling updating methods on the Cursor class, you must call commitUpdates() to send the changes to the database. To save a file, you can call ContentResolver().openOutputStream() with the URI as shown in the following snippet: Code: // Save the name and description in a map. Key is the content provider's // column name, value is the value to save in that record field. HashMap<String, Object> values = new HashMap<String, Object>(); values.put(Media.Images.NAME, "road_trip_1"); values.put(Media.Images.DESCRIPTION, "Day 1, trip to Los Angeles"); // Add a new record without the bitmap, but with the values. // It returns the URI of the new record. Uri uri = getContentResolver().insert(Media.Images.CONTENT_URI, values); // Now get a handle to the file for that record, and save the data into it. // sourceBitmap is a Bitmap object representing the file to save to the database. OutputStream outStream = getContentResolver.openOutputStream(uri); sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, outStream); outStream.close();
__________________ cheers Aman |
| |||
| Deleting a Record To delete a single record, call ContentResolver.delete() with the URI of a specific row, or call Cursor.deleteRow(). To delete multiple rows, call ContentResolver.delete() with the URI of the type of record to delete (for example, android.provider.Contacts.People.CONTENT_URI) and a SQL WHERE clause defining which rows to delete (Warning: be sure to include a valid WHERE clause if deleting a general type using ContentResolver.delete(), or else you risk deleting more records than you intended!). Remember, whenever calling updating methods on the Cursor class, you must call commitUpdates() to send the changes to the database.
__________________ cheers Aman |
| |||
| Network Accesses with Android In addition to all the on-device storage options, you can also store and retrieve data from the network (when available). To do network operations, you'll want to use the following packages: * java.net.* * android.net.*
__________________ cheers Aman |
| |||
| Writing Efficient Android Code There's no way around it: Android devices are embedded devices. Modern handsets may be more like small handheld computers than mere phones these days, but even the fastest, highest-end handset doesn't even come close to the capabilities of even a modest desktop system. That's why it's very important to consider performance when you write Android applications. These systems are not that fast to begin with and they are also constrained by their battery life. This means that there's not a lot of horsepower to spare, so when you write Android code it's important to write it as efficiently as possible. This page describes a number of things that developers can do to make their Android code run more efficiently. By following the tips on this page, you can help make sure your code runs as efficiently as possible. Contents * Introduction * Avoid Creating Objects * Use Native Methods * Prefer Virtual Over Interface * Prefer Static Over Virtual * Avoid Internal Getters/Setters * Cache Field Lookups * Declare Constants Final * Use Enhanced For Loop Syntax With Caution * Avoid Enums * Use Package Scope with Inner Classes * Avoid Float * Some Sample Performance Numbers * Closing Notes
__________________ cheers Aman |