Join Us on facebook just click on like..

Print This Code | Close This Window

Friday, November 16, 2012

Android Interviews


Android interview questions

What is an action?
The Intent Sender desires something or doing some task

What is activity?
A single screen in an application, with supporting Java code.

What is intent in Android?
A class (Intent) will describes what a caller desires to do. The caller will send this intent to Android's intent resolver, which finds the most suitable activity for the intent. E.g. opening a PDF document is an intent, and the Adobe Reader apps will be the perfect activity for that intent(class).

What is a Sticky Intent?
sendStickyBroadcast() performs a sendBroadcast (Intent) known as sticky, i.e. the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver (BroadcastReceiver, IntentFilter). In all other ways, this behaves the same as sendBroadcast(Intent).
One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.
Is there anyway to determine if an Intent passed into a BroadcastReceiver's onReceive is the result of a sticky Boradcast Intent, or if it was just sent?

Example for sticky broadcast
When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.

How the nine-patch Image different from a regular bitmap? or Different between nine-patch Image vs regular Bitmap Image
It is one of a resizable bitmap resource which is being used as backgrounds or other images on the device. The NinePatch class allows drawing a bitmap in nine sections. The four corners are unscaled; the middle of the image is scaled in both axes, the four edges are scaled into one axis.

What Programming languages does Android support for applicationdevelopment?
Android applications supports using Java Programming Language. which is coded in Java and complied using Android SDK.

What is a resource?
A user defined JSON, XML, bitmap, or other file, injected into the application build process, which can later be loaded from code.

How will you record a phone call in Android? or How to handle on Audio Stream for a call in Android?
Permissions.PROCESS_OUTGOING_CALLS: Will Allows an application to monitor, modify, or abort outgoing calls. So through that we can monitor the Phone calls.

What's the difference between class, file and activity in android?
Class - The Class file is complied from .java file. Android will use this .class fileto produce the executable apk.
File - It is a block of resources, srbitrary information. It can be any file type.
Activity - An activity is the equivalent of a Frame/Window in GUI toolkits. It is not a file or a file type it is just a class that can be extended in Android for loading UI elements on view.

Does Android support the Bluetooth serial port profile?
A. Yes.
Can an application be started on powerup?
A. Yes.

What is APK format.
The APK file is compressed AndroidManifest.xml file with extension .apk, Which have application code (.dex files), resource files, and other files which is compressed into single .apk file.

How to Translate in android
The Google translator translates the data of one language into another language by using XMPP to transmit data. You can type the message in English and select the language which is understood by the citizens of the country in order to reach the message to the citizens.

What is an action?
A description of something that an Intent sender desires.

What are the advantages of Android?
The following are the advantages of Android:

* The customer will be benefited from wide range of mobile applications to choose, since the monopoly of wireless carriers like Orange and AT&T will be broken by Google Android.
* Features like weather details, live RSS feeds, opening screen, icon on the opening screen can be customized
* Innovative products like the location-aware services, location of a nearby convenience store etc., are some of the additive facilities in Android.
What is the TTL (Time to Live)? Why is it required?
TTL is a value in data packet of Internet Protocol. It communicates to the network router whether or not the packet should be in the network for too long or discarded. Usually, data packets might not be transmitted to their intended destination within a stipulated period of time. The TTL value is set by a system default value which is an 8-bit binary digit field in the header of the packet. The purpose of TTL is, it would specify certain time limit in seconds, for transmitting the packet header. When the time is exhausted, the packet would be discarded. Each router receives the subtracts count, when the packet is discarded, and when it becomes zero, the router detects the discarded packets and sends a message, Internet Control Message Protocol message back to the originating host.
How is nine-patch image different from a regular bitmap?
It is a resizable bitmap resource that can be used for backgrounds or other images on the device. The NinePatch class permits drawing a bitmap in nine sections. The four corners are unscaled; the four edges are scaled in one axis, and the middle is scaled in both axes.
Explain IP datagram, Fragmentation and MTU ?
IP datagram can be used to describe a portion of IP data. Each IP datagram has set of fields arranged in an order. The order is specific which helps to decode and read the stream easily. IP datagram has fields like Version, header length, Type of service, Total length, checksum, flag, protocol, Time to live, Identification, source and destination ip address, padding, options and payload.
MTU:- Maximum Transmission Unit is the size of the largest packet that a communication protocol can pass. The size can be fixed by some standard or decided at the time of connection
Fragmentation is a process of breaking the IP packets into smaller pieces. Fragmentation is needed when the datagram is larger than the MTU. Each fragment becomes a datagram in itself and transmitted independently from source. When received by destination they are reassembled.
Explain about the exceptions of Android?
The following are the exceptions that are supported by Android
* InflateException : When an error conditions are occurred, this exception is thrown
* Surface.OutOfResourceException: When a surface is not created or resized, this exception is thrown
* SurfaceHolder.BadSurfaceTypeException: This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS
* WindowManager.BadTokenException: This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken.
Describe Android Application Architecture?
Android Application Architecture has the following components:
* Services ? like Network Operation
* Intent - To perform inter-communication between activities or services
* Resource Externalization - such as strings and graphics
Notification signaling users - light, sound, icon, notification, dialog etc.
* Content Providers - They share data between applications
What are the advantages of Android?
The following are the advantages of Android:
* The customer will be benefited from wide range of mobile applications to choose, since the monopoly of wireless carriers like AT&T and Orange will be broken by Google Android.
* Features like weather details, live RSS feeds, opening screen, icon on the opening screen can be customized
* Innovative products like the location-aware services, location of a nearby convenience store etc., are some of the additive facilities in Android.
How to select more than one option from list in android xml file? Give an example.
Specify android id, layout height and width as depicted in the following example.

Explain about the exceptions of Android?
The following are the exceptions that are supported by Android
* InflateException : When an error conditions are occurred, this exception is thrown
* Surface.OutOfResourceException: When a surface is not created or resized, this exception is thrown
* SurfaceHolder.BadSurfaceTypeException: This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS
* WindowManager.BadTokenException: This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken.
What are the features of Android?
*Components can be reused and replaced by the application framework.
*Optimized DVM for mobile devices
*SQLite enables to store the data in a structured manner.
*Supports GSM telephone and Bluetooth, WiFi, 3G and EDGE technologies
*The development is a combination of a device emulator, debugging tools, memory profiling and plug-in for Eclipse IDE.
What are the differences between a domain and a workgroup?
In a domain, one or more computer can be a server to manage the network. On the other hand in a workgroup all computers are peers having no control on each other. In a domain, user doesn?t need an account to logon on a specific computer if an account is available on the domain. In a work group user needs to have an account for every computer.
In a domain, Computers can be on different local networks. In a work group all computers needs to be a part of the same local network.
What is android?
Android is a stack of software for mobile devices which has Operating System,middleware and some key applications. The application executes within its own process and its own instance of Dalvik Virtual Machine. Many Virtual Machines run efficiently by a DVM device. DVM executes Java languages byte code which later transforms into .dex format files.
What is needed to make a multiple choice list with a custom view for each row?
Multiple choice list can be viewed by making the CheckBox android:id value be “@android:id /text1". That is the ID used by Android for the CheckedTextView in simple_list_item_multiple_choice.
What are the dialog boxes that are supported in android? Explain.
Android supports 4 dialog boxes:

AlertDialog : An alert dialog box supports 0 to 3 buttons and a list of selectable elements, including check boxes and radio buttons. Among the other dialog boxes, the most suggested dialog box is the alert dialog box.

ProgressDialog: This dialog box displays a progress wheel or a progress bar. It is an extension of AlertDialog and supports adding buttons.

DatePickerDialog: This dialog box is used for selecting a date by the user.

TimePickerDialog: This dialog box is used for selecting time by the user.
How to Remove Desktop icons and Widgets?
Press and Hold the icon or widget. The phone will vibrate and on the bottom of the phone you will see an option to remove. While still holding the icon or widget drag it to the remove button. Once remove turns red drop the item and it is gone
Common Tricky questions
  • Remember that the GUI layer doesn't request data directly from the web; data is always loaded from a local database.
  • The service layer periodically updates the local database.
  • What is the risk in blocking the Main thread when performing a lengthy operation such as web access or heavy computation? Application_Not_Responding exception will be thrown which will crash and restart the application.
  • Why is List View not recommended to have active components? Clicking on the active text box will pop up the software keyboard but this will resize the list, removing focus from the clicked element.
For senior employees
Beyond a certain level of experience, the job interview questions cease to be "difference between abstract class and interface", and focus more on testing your technical acumen, collaboration and communication skills. A list of such questions, typically asked during interviews for senior positions is given below:
  • Explain the life cycle of an application development process you worked on previously.
    What the interviewer looks for is communication of requirements, planning, modeling, construction and deployment on the back end.
  • Here's a hypothetical project. Explain how you would go about it.
    They want to know how you would break your work down into tasks and how many weeks for each task. I'm really looking to find out about planning methods, their skill set and how quickly they can execute.
  • How do you respond to requirement changes in the middle of a cycle?
  • What type of methodology have you used in the past? What are its drawbacks?
  • What are different techniques for prototyping an application?
    Similar question: Do you feel there is value in wireframing an application? Why?
  • How do you manage conflicts in Web applications when there are different people managing data?
  • Tell me something you learned from a team member in the last year.
  • What software testing procedures have you used to perform a QA?
Once the coding skills verified. Sample I
· The Activity life cycle is must. Ask about the different phases of Activity Life cycle. For example: when and how the activity comes to foreground?
· Check the knowledge on AndroidManifest file, For example: Why do we need this file, What is the role of this file in Android app development.
· Different Kinds of Intents
· Ask about different Kinds of context
· Ask about different Storage Methods in android
· Kinds of Log debugger and Debugger Configuration
· How to debug the application on real device.
· How do you ensure that the app design will be consistent across the different screen resolutions
· Thread concepts also plus points as we deal with the treads more.
· Can you able to build custom views and how?
· How to create flexible layouts, For example to place English, Chinese fonts.
· What is localization and how to achieve?
· What are 9-patch images
· How to avoid ANR status
· How to do Memory management
· Ask about IPC
· What is onCreate(Bundle savedInstanceState), Have you used savedInstanceState when and why?
· To check how updated the person is just ask about what are Fragments in an Activity
If this is an Android specific job, just ask the obvious stuff. Sample II
  • Application lifecycle
  • When to use a service
  • How to use a broadcast receiver and register it both in the manifest and in code
  • Intent filters
  • Stuff about what manifest attributes and tags mean
  • The types of flags to run an application
    • FLAG_ACTIVITY_NEW_TASK
    • FLAG_ACTIVITY_CLEAR_TOP
    • etc
  • How to do data intensive calculations using threads
  • Passing large objects (that can't be passed via intents and shouldn't be serialized) via a service
  • Binding to a service and the service lifecycle
  • How to persist data (both savedInstanceState and more permanent ways)

Sign android application (apk.)

Signing Your Applications using eclipse, ant, console

 

The Android system requires that all installed applications be digitally signed with a certificate whose private key is held by the application's developer. The Android system uses the certificate as a means of identifying the author of an application and establishing trust relationships between applications. The certificate is not used to control which applications the user can install. The certificate does not need to be signed by a certificate authority: it is perfectly allowable, and typical, for Android applications to use self-signed certificates.
The important points to understand about signing Android applications are:
  • All applications must be signed. The system will not install an application on an emulator or a device if it is not signed.
  • To test and debug your application, the build tools sign your application with a special debug key that is created by the Android SDK build tools.
  • When you are ready to release your application for end-users, you must sign it with a suitable private key. You cannot publish an application that is signed with the debug key generated by the SDK tools.
  • You can use self-signed certificates to sign your applications. No certificate authority is needed.
  • The system tests a signer certificate's expiration date only at install time. If an application's signer certificate expires after the application is installed, the application will continue to function normally.
  • You can use standard tools — Keytool and Jarsigner — to generate keys and sign your application .apk files.
  • After you sign your application for release, we recommend that you use the zipalign tool to optimize the final APK package.
The Android system will not install or run an application that is not signed appropriately. This applies wherever the Android system is run, whether on an actual device or on the emulator. For this reason, you must set up signing for your application before you can run it or debug it on an emulator or device.

Signing Process

 


The Android build process signs your application differently depending on which build mode you use to build your application. There are two build modes: debug mode and release mode. You use debug mode when you are developing and testing your application. You use release mode when you want to build a release version of your application that you can distribute directly to users or publish on an application marketplace such as Google Play.
When you build in debug mode the Android SDK build tools use the Keytool utility (included in the JDK) to create a debug key. Because the SDK build tools created the debug key, they know the debug key's alias and password. Each time you compile your application in debug mode, the build tools use the debug key along with the Jarsigner utility (also included in the JDK) to sign your application's .apk file. Because the alias and password are known to the SDK build tools, the tools don't need to prompt you for the debug key's alias and password each time you compile.
When you build in release mode you use your own private key to sign your application. If you don't have a private key, you can use the Keytool utility to create one for you. When you compile your application in release mode, the build tools use your private key along with the Jarsigner utility to sign your application's .apk file. Because the certificate and private key you use are your own, you will have to provide the password for the keystore and key alias.
The debug signing process happens automatically when you run or debug your application using Eclipse with the ADT plugin. Debug signing also happens automatically when you use the Ant build script with the debug option. You can automate the release signing process by using the Eclipse Export Wizard or by modifying the Ant build script and building with the release option.



Through Command line: 

 

use this command, (go to java < jdk < bin path in cmd prompt) write the command
$ jarsigner -verify -verbose -certs my_application.apk

If you see "CN=Android Debug", this means the .apk was signed with the debug key generated by the Android SDK (means it is unsigned), else u will find something for CN. for more details
http://developer.android.com/guide/publishing/app-signing.html


if you are eclipse User

 

Right-click your project in Eclipse > Chose Android Tool > Export Signed Application Package.


if you are Ant User 

 

If you have ant version < 1.8.3 (ant -version) try this approach for issue with JDK 7 basing previous answer.
  1. Add signjarjdk7 to ANDROID_SDK\tools\ant\build.xml
    <macrodef name="signjarjdk7">
        <attribute name="jar" />
        <attribute name="signedjar" />
        <attribute name="keystore" />
        <attribute name="storepass" />
        <attribute name="alias" />
        <attribute name="keypass" />
        <attribute name="verbose" />
        <sequential>
            <exec executable="jarsigner" failonerror="true">
                <!-- magic key, always verbose -->
                <arg line="-verbose -digestalg SHA1 -sigalg MD5withRSA" />                      
                <arg line="-keystore @{keystore} -storepass @{storepass} -keypass @{keypass}" />
                <arg line="-signedjar &quot;@{signedjar}&quot;" />
                <arg line="&quot;@{jar}&quot; @{alias}" />
            </exec>
        </sequential>
    </macrodef>
  2. Replace 'signjar' to 'signjarjdk7' in 'release' target in the same build.xml.
NOTE: You have to define 'key.store.password' and 'key.alias.password' propeties for your project (in project.properties or in local.properties).
Update:
If your have installed ant-1.8.3+ you have better solution:
Open you ANDROID_SDK\tools\ant\build.xml and add two new parameters - sigalg and digestalg - in original 'signjar' invocation:
    <signjar
            sigalg="MD5withRSA"
            digestalg="SHA1"
            jar="${out.packaged.file}"
            signedjar="${out.unaligned.file}"
            keystore="${key.store}"
            storepass="${key.store.password}"
            alias="${key.alias}"
            keypass="${key.alias.password}"
            verbose="${verbose}" />
 

                                                              OR

Signing application automatically with password in ant :

 

I just have these lines in my ant.properties and it signs automatically
key.store.password=mypasswordOne
key.alias.password=mypasswordTwo
key.store=c:/users/myname/my-release-key.keystore
key.alias=release_alias
 

Expiry of the Debug Certificate

 

The self-signed certificate used to sign your application in debug mode (the default on Eclipse/ADT and Ant builds) will have an expiration date of 365 days from its creation date.
When the certificate expires, you will get a build error. On Ant builds, the error looks like this:
debug: [echo] Packaging bin/samples-debug.apk, and signing it with a debug key... [exec] Debug Certificate expired on 8/4/08 3:43 PM In Eclipse/ADT, you will see a similar error in the Android console.
To fix this problem, simply delete the debug.keystore file. The default storage location for AVDs is in ~/.android/ on OS X and Linux, in C:\Documents and Settings\<user>\.android\ on Windows XP, and in C:\Users\<user>\.android\ on Windows Vista and Windows 7.
The next time you build, the build tools will regenerate a new keystore and debug key.
Note that, if your development machine is using a non-Gregorian locale, the build tools may erroneously generate an already-expired debug certificate, so that you get an error when trying to compile your application. For workaround information, see the troubleshooting topic I can't compile my app because the build tools generated an expired debug certificate.
 

 



Android Receive SMS Using Broadcast Receiver

 

The first are permissions . The application  must receive, from the database.   

Permissions can be set in Manifest.xml like:

    <uses-permission android:name="android.permission.RECEIVE_SMS" />


Now our Activity class SMSreceiver is here...

private class SMSreceiver extends BroadcastReceiver
{
  private final String TAG = this.getClass().getSimpleName();
  @Override
  public void onReceive(Context context, Intent intent)
  {
     Bundle extras = intent.getExtras();
     String strMessage = "";
     if ( extras != null )
     {
        Object[] smsextras = (Object[]) extras.get( "pdus" );
        for ( int i = 0; i < smsextras.length; i++ )
        {
           SmsMessage smsmsg = SmsMessage.createFromPdu((byte[])smsextras[i]);
           String strMsgBody = smsmsg.getMessageBody().toString();
           String strMsgSrc = smsmsg.getOriginatingAddress();  
           strMessage += "SMS from " + strMsgSrc + " : " + strMsgBody;                    
           Log.i(TAG, strMessage);
         }
      }

    }

}

Thursday, October 18, 2012

MapView Tutorial

MapView Tutorial

Using the Google Maps library, you can create your own map-viewing Activity. In this tutorial, you'll create a simple map application in two parts. In Part 1, you'll create an app that shows a map the user can pan and zoom. In Part 2, you'll add overlay items that mark points of interest.
This tutorial requires that you have the external Google Maps library installed in your SDK environment. The Maps library is included with the Google APIs add-on, which you can install using the Android SDK and AVD Manager. To learn how, see Installing the Google APIs Add-On.
After installing the Google APIs add-on in your SDK, set your project properties to use the build target called "Google APIs by Google Inc.". See the instructions for setting a build target in Creating and Managing Projects in Eclipse or Creating and Managing Projects on the Command Line, as appropriate for your environment.
You will also need to set up a new AVD that uses the same Google APIs deployment target. See Creating and Managing Virtual Devices for more information.
For reference material, see the Google Maps library documentation.

Part 1: Creating a Map Activity

  1. Start a new project named HelloGoogleMaps.
  2. Because the Maps library is not a part of the standard Android library, you must declare it in the Android Manifest. Open the AndroidManifest.xml file and add the following as a child of the <application> element:
    <uses-library android:name="com.google.android.maps"/>
  3. You also need access to the Internet in order to retrieve map tiles, so you must also request the INTERNET permission. In the manifest file, add the following as a child of the <manifest> element:
    <uses-permission android:name="android.permission.INTERNET"/>
  4. While you're in the manifest, give the map some more space by getting rid of the title bar with the "NoTitleBar" theme:
    <activity android:name=".HelloGoogleMaps" android:label="@string/app_name"
         android:theme="@android:style/Theme.NoTitleBar">
    
  5. Open the res/layout/main.xml file and add a single MapView as the root node:
    <?xml version="1.0" encoding="utf-8"?>
    <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="Your Maps API Key goes here"
    />
    
    The android:clickable attribute defines whether you want to allow user-interaction with the map. If this is "false" then touching the map does nothing.
    The android:apiKey attribute holds the Maps API Key for your application, which proves your application and signer certificate has been registered with the Maps service. This is required in order to receive the map data, even while you are developing. Registration to the service is free and it only takes a couple minutes to register your certificate and get a Maps API Key.
    Go now to get a key. For instructions, read Obtaining a Maps API Key. For the purpose of this tutorial, you should register with the SDK debug certificate, as described in Getting the MD5 Fingerprint of the SDK Debug Certificate. Please note that this is only valid while your application is signed with the debug key; once you sign with your private key, you will need a new API key. When you get your key, insert it for the value of android:apiKey.
  6. Now open the HelloGoogleMaps.java file. For this Activity, extend MapActivity instead of android.app.Activity:
    public class HelloGoogleMaps extends MapActivity
    MapActivity is a special sub-class of Activity, provided by the Maps library, which provides important map capabilities.
  7. Inside every MapActivity, the isRouteDisplayed() method is required, so override this method:
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
    
    This method is required for some accounting from the Maps service to see if you're currently displaying any route information. In this case, you're not, so return false.
  8. Now add the standard onCreate() callback method to the class:
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    This loads the layout file created above. In fact, this is now a workable application that will display map tiles and allow the user to pan around the map. But there's no ability to zoom. Fortunately, there's a very simple zoom feature built into the MapView class, which you can include by calling setBuiltInZoomControls(). Do this at the end of the onCreate() method definition:
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
    
  9. That's all there is to it. Run the application. Remember, you must have an AVD configured to use the Google APIs target, or be using a development device that includes the Maps library.

Part 2: Adding Overlay Items

So, now you have a map, but in many cases you'll also want to create your own map markers and lay-overs. That's what you'll do now. In order to do so, you must implement the ItemizedOverlay class, which can manage a whole set of Overlay objects (the individual items placed on the map).
  1. Create a new Java class named HelloItemizedOverlay that extends ItemizedOverlay: When using Eclipse, right-click the package name in the Eclipse Package Explorer, and select New > Class. Set the Name field to HelloItemizedOverlay. For Superclass, enter "com.google.android.maps.ItemizedOverlay. Click the checkbox for Constructors from superclass. Click Finish.
  2. First, you need an OverlayItem ArrayList, in which you'll put each of the OverlayItem objects you want on the map. Add this at the top of the HelloItemizedOverlay class:
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
  3. Now define the HelloItemizedOverlay constructors. The constructor must define the default marker for each of the OverlayItem objects. In order for the Drawable to actually get drawn, it must have its bounds defined. Most commonly, you want the center-point at the bottom of the image to be the point at which it's attached to the map coordinates. This is handled for you with the boundCenterBottom() method. Wrap this around the defaultMarker, so the super constructor call looks like this:
    public HelloItemizedOverlay(Drawable defaultMarker) {
      super(boundCenterBottom(defaultMarker));
    }
    
  4. In order to add new OverlayItem objects to the ArrayList, you need a new method:
    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }
    Each time you add a new OverlayItem to the ArrayList, you must call populate() for the ItemizedOverlay, which will read each of the OverlayItem objects and prepare them to be drawn.
  5. When the populate() method executes, it will call createItem(int) in the ItemizedOverlay to retrieve each OverlayItem. You must override this method to properly read from the ArrayList and return the OverlayItem from the position specified by the given integer. Your override method should look like this:
    @Override
    protected OverlayItem createItem(int i) {
      return mOverlays.get(i);
    }
    
  6. You must also override the size() method to return the current number of items in the ArrayList:
    @Override
    public int size() {
      return mOverlays.size();
    }
    
  7. Now set up the ability to handle touch events on the overlay items. First, you're going to need a reference to the application Context as a member of this class. So add Context mContext as a class member, then initialize it with a new class constructor:
    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
      super(boundCenterBottom(defaultMarker));
      mContext = context;
    }
    
    This passes the defaultMarker up to the default constructor to bound its coordinates and then initializes mContext with the given Context.
    Then override the onTap() callback method, which will handle the event when an item is tapped by the user:
    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }
    
    This uses the member android.content.Context to create a new AlertDialog.Builder and uses the tapped OverlayItem's title and snippet for the dialog's title and message text. (You'll see the OverlayItem title and snippet defined when you create it below.)
You're now done with the HelloItemizedOverlay class and can start using it to add items on the map.
Go back to the HelloGoogleMaps class. In the following procedure, you'll create an OverlayItem and add it to an instance of the HelloItemizedOverlay class, then add the HelloItemizedOverlay to the MapView using a GeoPoint to define its coordinates on the map.
  1. First, you need the image for the map overlay. If you don't have one handy, use the Android on the right. Drag this image (or your own) into the res/drawable/ directory of your project.
  2. At the end of your existing onCreate() method, instantiate :
    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
    
    All overlay elements on a map are held by the MapView, so when you want to add some, you have to get a list from the getOverlays() method. Then instantiate the Drawable used for the map marker, which was saved in the res/drawable/ directory. The constructor for HelloItemizedOverlay (your custom ItemizedOverlay) takes the Drawable in order to set the default marker for all overlay items.
  3. Now create a GeoPoint that defines the map coordinates for the first overlay item, and pass it to a new {@code OverlayItem}:
    GeoPoint point = new GeoPoint(19240000,-99120000);
    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
    
    GeoPoint coordinates are specified in microdegrees (degrees * 1e6). The OverlayItem constructor accepts the GeoPoint location, a string for the item's title, and a string for the item's snippet text, respectively.
  4. All that's left is to add this OverlayItem to your collection in the HelloItemizedOverlay instance, then add the HelloItemizedOverlay to the MapView:
    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
    
  5. Now run the application.
You should see the following:
When you tap the overlay item, you'll see the dialog appear.
Because the ItemizedOverlay class uses an java.util.ArrayList for all of the OverlayItem objects, it's easy to add more. Try adding another one. Before the addOverlay() method is called, add these lines:
GeoPoint point2 = new GeoPoint(35410000, 139460000);
OverlayItem overlayitem2 = new OverlayItem(point2, "Sekai, konichiwa!", "I'm in Japan!");

Friday, June 15, 2012

How to Install Windows 95, 98, XP on Android Phone



Have you always wanted to use Windows or Linux on your smartphone? Then you are right, because today we want to tell you about a fantastic app that allows to do this.
The application was created by a developer at XDA and called Bochs Pentium emulator, its inventor says that operating systems are tested and working for Windows95.98, XP and some distributions Linux, tested on smartphone Android HTC Evo 3D.

1st Idea :

 HTC EVO 3D or You can try this on another android phones.

Pre-requisites: Windows 95/98/XP Image: ISO or .IMG. (IMG preferred and tested).

Step 1. Download bochs.apk [mirror] and SDL.zip [mirror]. Put SDL.zip on root of sdcard/

Step 2. Put the Windows 95/98/XP disk image .img/.iso [(need to change setting in bochsrc.txt accordingly (iso not tested yet)] of any operating system in SDL folder and rename it to “c.img”.

Step 3. Run Bochs apk. Let it boot (takes a while) and enjoy.

Note: Use this bochsrc.txt to use a folder called “HDD” on your sdcard as a drive in windows. Replace the original bochsrc.txt withthe one stated before. Further updates on xda thread.
Instructions for input controls are as follows:
  • To emulate touchpad on touchscreen and left/right mouse buttons on volume
  • You can also click touch screen to generate mouse left button click.(this does not work everytime)
  • Back = BackSpace, Menu = Enter, left-upper corner click generates TAB
  • left-lower corner click popups keyboard


2st Idea For All Android Phones :





3rd Idea For All Android Phones :



The first thing to do is downloading of the file to install apk files and SD from the following links:
SDL.zip
SDLapp.apk
Once downloaded, Extract the first zip, create a folder called SDL in the root of the device and copy your files extracted from the first zip file and apk by using Smartphone with Archive, ES File or any other file manager, go to the directory created and started to install the apk.
Windows XP on Android
Once the installation process is finished, make the iso compatible operating system such as XP, and then rename c.img, place it in the same directory with SDL. Launch the app and have fun!
Obviously launching a XP os is equivalent to consume lots of RAM and space on your mobile device, but if you want to impress your friends then this app is really for you.

Tuesday, March 20, 2012

Android Styles and Themes

A style is a collection of properties that specify the look and format for a View or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.
Styles in Android share a similar philosophy to cascading stylesheets in web design—they allow you to separate the design from the content.

For example, by using a style, you can take this layout XML:

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="@string/hello" />

And turn it into this:
<TextView
style="@style/CodeFont"
android:text="@string/hello" />

All of the attributes related to style have been removed from the layout XML and put into a style definition called CodeFont, which is then applied with the style attribute. You'll see the definition for this style in the following section.

A theme is a style applied to an entire Activity or application, rather than an individual View (as in the example above). When a style is applied as a theme, every View in the Activity or application will apply each style property that it supports. For example, you can apply the same CodeFont style as a theme for an Activity and then all text inside that Activity will have green monospace font.
Defining Styles

To create a set of styles, save an XML file in the res/values/ directory of your project. The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder.
The root node of the XML file must be <resources>.

For each style you want to create, add a <style> element to the file with a name that uniquely identifies the style (this attribute is required). Then add an <item> element for each property of that style, with a name that declares the style property and a value to go with it (this attribute is required). The value for the <item> can be a keyword string, a hex color, a reference to another resource type, or other value depending on the style property. Here's an example file with a single style:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>

Each child of the <resources> element is converted into an application resource object at compile-time, which can be referenced by the value in the <style> element's name attribute. This example style can be referenced from an XML layout as @style/CodeFont (as demonstrated in the introduction above).

The parent attribute in the <style> element is optional and specifies the resource ID of another style from which this style should inherit properties. You can then override the inherited style properties if you want to.
Remember, a style that you want to use as an Activity or application theme is defined in XML exactly the same as a style for a View. A style such as the one defined above can be applied as a style for a single View or as a theme for an entire Activity or application. How to apply a style for a single View or as an application theme is discussed later.
Inheritance

The parent attribute in the <style> element lets you specify a style from which your style should inherit properties. You can use this to inherit properties from an existing style and then define only the properties that you want to change or add. You can inherit from styles that you've created yourself or from styles that are built into the platform. (See Using Platform Styles and Themes, below, for information about inheriting from styles defined by the Android platform.) For example, you can inherit the Android platform's default text appearance and then modify it:

<style name="GreenText" parent="@android:style/TextAppearance">
<item name="android:textColor">#00FF00</item>
</style>

If you want to inherit from styles that you've defined yourself, you do not have to use the parent attribute. Instead, just prefix the name of the style you want to inherit to the name of your new style, separated by a period. For example, to create a new style that inherits the CodeFont style defined above, but make the color red, you can author the new style like this:
<style name="CodeFont.Red">
<item name="android:textColor">#FF0000</item>
</style>
Notice that there is no parent attribute in the <style> tag, but because the name attribute begins with the CodeFont style name (which is a style that you have created), this style inherits all style properties from that style. This style then overrides the android:textColor property to make the text red. You can reference this new style as @style/CodeFont.Red.
You can continue inheriting like this as many times as you'd like, by chaining names with periods. For example, you can extend CodeFont.Red to be bigger, with:
<style name="CodeFont.Red.Big">
<item name="android:textSize">30sp</item>
</style>

This inherits from both CodeFont and CodeFont.Red styles, then adds the android:textSize property.
Note: This technique for inheritance by chaining together names only works for styles defined by your own resources. You can't inherit Android built-in styles this way. To reference a built-in style, such as TextAppearance, you must use the parent attribute.
Style Properties

Now that you understand how a style is defined, you need to learn what kind of style properties—defined by the <item> element—are available. You're probably familiar with some already, such as layout_width and textColor. Of course, there are many more style properties you can use.
The best place to find properties that apply to a specific View is the corresponding class reference, which lists all of the supported XML attributes. For example, all of the attributes listed in the table of TextView XML attributes can be used in a style definition for a TextView element (or one of its subclasses). One of the attributes listed in the reference is android:inputType, so where you might normally place the android:inputType attribute in an <EditText> element, like this:

<EditText
android:inputType="number"
... />
You can instead create a style for the EditText element that includes this property:
<style name="Numbers">
<item name="android:inputType">number</item>
...
</style>
So your XML for the layout can now implement this style:
<EditText
style="@style/Numbers"
... />

This simple example may look like more work, but when you add more style properties and factor-in the ability to re-use the style in various places, the pay-off can be huge.
For a reference of all available style properties, see the R.attr reference. Keep in mind that all View objects don't accept all the same style attributes, so you should normally refer to the specific View class for supported style properties. However, if you apply a style to a View that does not support all of the style properties, the View will apply only those properties that are supported and simply ignore the others.

Some style properties, however, are not supported by any View element and can only be applied as a theme. These style properties apply to the entire window and not to any type of View. For example, style properties for a theme can hide the application title, hide the status bar, or change the window's background. These kind of style properties do not belong to any View object. To discover these theme-only style properties, look at the R.attr reference for attributes that begin with window. For instance, windowNoTitle and windowBackground are style properties that are effective only when the style is applied as a theme to an Activity or application. See the next section for information about applying a style as a theme.

Note: Don't forget to prefix the property names in each <item> element with the android: namespace. For example: <item name="android:inputType">.
Applying Styles and Themes to the UI
There are two ways to set a style:
• To an individual View, by adding the style attribute to a View element in the XML for your layout.
• Or, to an entire Activity or application, by adding the android:theme attribute to the <activity> or <application> element in the Android manifest.
When you apply a style to a single View in the layout, the properties defined by the style are applied only to that View. If a style is applied to a ViewGroup, the child View elements will not inherit the style properties—only the element to which you directly apply the style will apply its properties. However, you can apply a style so that it applies to all View elements—by applying the style as a theme.

To apply a style definition as a theme, you must apply the style to an Activity or application in the Android manifest. When you do so, every View within the Activity or application will apply each property that it supports. For example, if you apply the CodeFont style from the previous examples to an Activity, then all View elements that support the text style properties will apply them. Any View that does not support the properties will ignore them. If a View supports only some of the properties, then it will apply only those properties.
Apply a style to a View
Here's how to set a style for a View in the XML layout:

<TextView
style="@style/CodeFont"
android:text="@string/hello" />
Now this TextView will be styled as defined by the style named CodeFont. (See the sample above, in Defining Styles.)
Note: The style attribute does not use the android: namespace prefix.
Apply a theme to an Activity or application
To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the <application> tag to include the android:theme attribute with the style name. For example:
<application android:theme="@style/CustomTheme">

If you want a theme applied to just one Activity in your application, then add the android:theme attribute to the <activity> tag instead.
Just as Android provides other built-in resources, there are many pre-defined themes that you can use, to avoid writing them yourself. For example, you can use the Dialog theme and make your Activity appear like a dialog box:

<activity android:theme="@android:style/Theme.Dialog">
Or if you want the background to be transparent, use the Translucent theme:
<activity android:theme="@android:style/Theme.Translucent">
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional light theme to use your own color like this:
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>

(Note that the color needs to supplied as a separate resource here because the android:windowBackground attribute only supports a reference to another resource; unlike android:colorBackground, it can not be given a color literal.)
Now use CustomTheme instead of Theme.Light inside the Android Manifest:
<activity android:theme="@style/CustomTheme">

Select a theme based on platform version
Newer versions of Android have additional themes available to applications, and you might want to use these while running on those platforms while still being compatible with older versions. You can accomplish this through a custom theme that uses resource selection to switch between different parent themes, based on the platform version.

For example, here is the declaration for a custom theme which is simply the standard platforms default light theme. It would go in an XML file under res/values (typically res/values/styles.xml):
<style name="LightThemeSelector" parent="android:Theme.Light">
...
</style>
To have this theme use the newer holographic theme when the application is running on Android 3.0 (API Level 11) or higher, you can place an alternative declaration for the theme in an XML file in res/values-v11, but make the parent theme the holographic theme:
<style name="LightThemeSelector" parent="android:Theme.Holo.Light">
...
</style>

Now use this theme like you would any other, and your application will automatically switch to the holographic theme if running on Android 3.0 or higher.
A list of the standard attributes that you can use in themes can be found at R.styleable.Theme.
For more information about providing alternative resources, such as themes and layouts, based on the platform version or other device configurations, see the Providing Resources document.
Using Platform Styles and Themes

The Android platform provides a large collection of styles and themes that you can use in your applications. You can find a reference of all available styles in the R.style class. To use the styles listed here, replace all underscores in the style name with a period. For example, you can apply the Theme_NoTitleBar theme with "@android:style/Theme.NoTitleBar".
The R.style reference, however, is not well documented and does not thoroughly describe the styles, so viewing the actual source code for these styles and themes will give you a better understanding of what style properties each one provides. For a better reference to the Android styles and themes, see the following source code:
• Android Styles (styles.xml)
• Android Themes (themes.xml)

These files will help you learn through example. For instance, in the Android themes source code, you'll find a declaration for <style name="Theme.Dialog">. In this definition, you'll see all of the properties that are used to style dialogs that are used by the Android framework.
For more information about the syntax used to create styles in XML, see Available Resource Types: Style and Themes.

For a reference of available style attributes that you can use to define a style or theme (e.g., "windowBackground" or "textAppearance"), see R.attr or the respective View class for which you are creating a style.