Friday 29 November 2013

Android Soft Keyboard Resizes Web View in Phonegap

         Android soft keyboard resize the  web view and css get misaligned when focus on the textbox.

To solve this problem by following this steps:

1. Go to your Android application directory.

2. Open  AndroidManifest.xml
  
3. Add   android:windowSoftInputMode="adjustPan to <activity>

Code Below:

 <!-- Before -->
  <activity android:configChanges="orientation|keyboardHidden" 
android:label="@string/app_name" android:name="PhotoGap">

  <!-- After -->
  <activity android:configChanges="orientation|keyboardHidden" 
android:windowSoftInputMode="adjustPan" android:label="@string/app_name"
 android:name="PhonegapDemo">

For More Info:Click Here

Friday 22 November 2013

Developing Mobile Applications: Web, Native, or Hybrid

Native apps :
                         Native mobile Applications are the applications build using the native language of the mobile and can be deployed to a specified store,  for example if we want to build native android application we have to know java and using java and android sdk we can build native android app and can only be deployed android market(Play Store). where as iphone applications can be developed by a c++ proggramer and can be only deployed itunes.coming to portability Native apps are platform dependent.coming to cost native apps are cost as we need different programmers for devloping different native apps and every application need to be deployed in it's own market store and we have to pay for diploying our applications. Comparing to others native applications are fast , user interactive, provide good apperance and also deploying to market stores makes your application reachable to users easily.

Start your code by refer this link: Native Applications

Hybrid apps :
                    Hybrid Apps are the applications build using HTML5 And JavaScript and deployed to any mobile os store by just changing some configurations and this is done by some opensource frameworks like PhoneGap. PhoneGap is a framework that consists of different libraries which can convert a web application into native application and uses native apps webview and display the webapp in the webview and makes work as native apps.it is platform independent (but need to change some configurations while deploying).

It solves many disadvantages seen in webapplications and native applications.cost is less then native apps,can be deployed in market stores like playstore,itunes,ovi.Mobile hardware can be accessed by hybrid apps as native apps uses.user interactivity is good any web developer can build this hybrid apps with some additional things.user interactivity is good,appearence is good,reusability.

Mobile web
                     Web Applications are simple applications build using HTML5 and JavaScript and can be deployed in our own webservers. Any mobile user can use this application from their mobile browser. Compared to native apps this applications are low cost and can be used by any mobile user it is platform independent. Compared to native apps web apps are slow,appearence is not good as native apps,we cannot use mobile hardware like camera,gps,sensors.any web developer can develop web apps and can deploy the apps in their own web server and can be accessed by any mobile os devices.

Native mobile apps advantages and disadvantages
Advantages
    1. High performance, it delivers the best user experience
    2. It can be easily discovered in the app stores
    3. It offers full access to the mobile platform

Disadvantages
1. You need different knowledge for each target platform
2. These apps are usually the most expensive to develop, as you need to hire talent experienced in       each platform.
3. You cannot re-use code between platforms

Hybrid mobile apps advantages and disadvantages
Advantages
 1. It’s easy to develop, you won’t have a hard time finding an app developer
 2. Code base is re-usable between mobile platforms
 3. Overall lower budget costs

Disadvantages
1. Native mobile apps will always provide a better user experience; hybrid just doesn’t look or feel as smooth and natural
2. Hybrid mobile apps need distinct web view implementations per platform
3. you’ll probably spend way too much time fixing it




Wednesday 20 November 2013

Play youtube Video in android



Here's the code to play YouTube videos in WebView using video url.

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".VideoActivity" >

    <Button
        android:id="@+id/btnPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|top"
        android:layout_margin="5dp" />

    <WebView
        android:id="@+id/videoView"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Youtube Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.youtube"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.youtube.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

YoutubeActivity.java

package com.example.youtube;

import android.app.Activity;
import android.content.Context;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.widget.VideoView;

public class MainActivity extends Activity {
    public static final int USER_MOBILE = 0;
    public static final int USER_DESKTOP = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
final WebView video = (WebView) findViewById(R.id.videoView);
Button btnPlay = (Button) findViewById(R.id.btnPlay);
btnPlay.setText("Play Video");

btnPlay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
video.getSettings().setJavaScriptEnabled(true);
video.getSettings().setPluginState(WebSettings.PluginState.ON);
 //video.getSettings().getDefaultUserAgent(USER_MOBILE);
video.setWebChromeClient(new WebChromeClient() {
});

//youtube video url
////http://www.youtube.com/watch?v=WM5HccvYYQg

 final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = getHTML("PT8zRmrUTrA");

video.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
});
}


public String getHTML(String videoId) {

String html =
"<iframe class=\"youtube-player\" "
+ "style=\"border: 0; width: 100%; height: 95%;"
+ "padding:0px; margin:0px\" "
+ "id=\"ytplayer\" type=\"text/html\" "
+ "src=\"http://www.youtube.com/embed/" + videoId
+ "?fs=0\" frameborder=\"0\" " + "allowfullscreen autobuffer "
+ "controls onclick=\"this.play()\">\n" + "</iframe>\n";



return html;
}

}

Tuesday 19 November 2013

Log in\ Log out Session Management using shared Preferences in Android


                               Session are useful when you want to store user data globally through out the application. This can be done in two ways. One is storing them in a global variables and second is storing the data in shared preferences. The problem with storing data in global variable is data will be lost once user closes the application, but storing the data in shared preferences will be persistent even though user closes the application.


               Application shared preferences allows you to save and retrieve key, value pair data. Before getting into tutorial, I am giving basic information needed to work with shared preferences.

Initialization

Application shared preferences can be fetched using getSharedPreferences() method.You also need an editor to edit and save the changes in shared preferences. The following code can be used to get application shared preferences.
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
Editor editor = pref.edit();

Storing Data

You can save data into shared preferences using editor. All the primitive data types like booleans, floats, ints, longs, and strings are supported. Call editor.commit() in order to save changes to shared preferences.
editor.putBoolean("key_name", true); // Storing boolean - true/false
editor.putString("key_name", "string value"); // Storing string
editor.putInt("key_name", "int value"); // Storing integer
editor.putFloat("key_name", "float value"); // Storing float
editor.putLong("key_name", "long value"); // Storing long
  
editor.commit(); // commit changes

Retrieving Data

Data can be retrived from saved preferences by calling getString() (For string) method. Remember this method should be called on Shared Preferences not on Editor.
// returns stored preference value
// If value is not present return second param value - In this case null
pref.getString("key_name", null); // getting String
pref.getInt("key_name", null); // getting Integer
pref.getFloat("key_name", null); // getting Float
pref.getLong("key_name", null); // getting Long
pref.getBoolean("key_name", null); // getting boolean

Clearing / Deleting Data

If you want to delete from shared preferences you can call remove(“key_name”) to delete that particular value. If you want to delete all the data, call clear()
editor.remove("name"); // will delete key name
editor.remove("email"); // will delete key email
  
editor.commit(); // commit changes
Following will clear all the data from shared preferences
editor.clear();
editor.commit(); // commit changes


The following is a simple tutorial which will have a login form and a dashboard screen. At first user will login using login details and once he successfully logged in his credentials (name, email) will be stored in shared preferences.

Download code from this Link: Session Management

Saturday 16 November 2013

Enable/Disable Mobile Data in Android

               This post will explain about  enable/disable mobile internet data programmatically in android


1. activity_mobile_data.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ToggleButton
        android:id="@+id/tBMobileData"
        android:layout_width="300dp"
        android:layout_height="150dp"
        android:layout_centerInParent="true"
        android:textSize="30sp"
        android:textOff="Enable"
        android:textOn="Disable" />

    <TextView
        android:id="@+id/TVMobileData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/tBMobileData"
        android:layout_alignParentLeft="true"
        android:text="Mobile Data: Disable"
        android:textColor="#1BD6E0"
        android:textSize="40sp" />

</RelativeLayout>

2. AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mobiledata"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.mobiledata.MobileData"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>


3. MobileData.Java
package com.example.mobiledata;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.ToggleButton;

import android.app.Activity;
import android.view.Menu;

public class MobileData extends Activity {
    static final String STATUS_ON = "Mobile Data: Enable";
     static final String STATUS_OFF = "Mobile Data: Disable";

     static final String TURN_ON = "Enable";
     static final String TURN_OFF = "Disable";

     // controls
     TextView TVMobileData;
     ToggleButton tBMobileData;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mobile_data);
       
     // load controls
        TVMobileData=(TextView)findViewById(R.id.TVMobileData);
        tBMobileData=(ToggleButton)findViewById(R.id.tBMobileData);

        // set click event for button
        tBMobileData.setOnClickListener(new OnClickListener() {                    
         @Override
         public void onClick(View v) {
          // check current state first
          boolean state = isMobileDataEnable();
          // toggle the state
          if(state)toggleMobileDataConnection(false);
          else toggleMobileDataConnection(true);
          // update UI to new state
          updateUI(!state); 
         }
        });
       }
       public void updateUI(boolean state) {
        //set text according to state
        if(state) {
         TVMobileData.setText(STATUS_ON);
         tBMobileData.setText(TURN_OFF);            
        } else {
         TVMobileData.setText(STATUS_OFF);
         tBMobileData.setText(TURN_ON);
        }
       }
       public boolean isMobileDataEnable() {
        boolean mobileDataEnabled = false; // Assume disabled
        ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
        try {
         Class<?> cmClass = Class.forName(cm.getClass().getName());
         Method method = cmClass.getDeclaredMethod("getMobileDataEnabled");
         method.setAccessible(true); // Make the method callable
         // get the setting for "mobile data"
         mobileDataEnabled = (Boolean)method.invoke(cm);
        } catch (Exception e) {
         // Some problem accessible private API and do whatever error handling you want here
        }
        return mobileDataEnabled;
       }
       public boolean toggleMobileDataConnection(boolean ON)
       {
        try {
         //create instance of connectivity manager and get system connectivity service
         final ConnectivityManager conman = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
         //create instance of class and get name of connectivity manager system service class
         final Class<?> conmanClass  = Class.forName(conman.getClass().getName());
         //create instance of field and get mService Declared field
         final Field iConnectivityManagerField= conmanClass.getDeclaredField("mService");
         //Attempt to set the value of the accessible flag to true
         iConnectivityManagerField.setAccessible(true);
         //create instance of object and get the value of field conman
         final Object iConnectivityManager = iConnectivityManagerField.get(conman);
         //create instance of class and get the name of iConnectivityManager field
         final Class<?> iConnectivityManagerClass=  Class.forName(iConnectivityManager.getClass().getName());
         //create instance of method and get declared method and type
         final Method setMobileDataEnabledMethod= iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled",Boolean.TYPE);
         //Attempt to set the value of the accessible flag to true
         setMobileDataEnabledMethod.setAccessible(true);
         //dynamically invoke the iConnectivityManager object according to your need (true/false)
         setMobileDataEnabledMethod.invoke(iConnectivityManager, ON);
        } catch (Exception e){
        }
        return true;
       }
      }

Friday 15 November 2013

Android Interview questions and answers -Part 1

1.What is android?
A. 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 language?s byte code which later transforms into .dex format files.

2.What are the advantages of Android?
A. 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.
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.

3.Explain about the exceptions of Android?
A. 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.

4.Describe the APK format.
A. The APK file is compressed the AndroidManifest.xml file, application code (.dex files), resource files, and other files. A project is compiled into a single .apk file.

5.What is .apk extension?
A. The extension for an Android package file, which typically contains all of the files related to a single Android application. The file itself is a compressed collection of an AndroidManifest.xml file, application code (.dex files), resource files, and other files. A project is compiled into a single .apk file.

 6.What is .dex extension?
A. Android programs are compiled into .dex (Dalvik Executable) files,
which are in turn zipped into a single .apk file on the device. .dex
 files can be created by automatically translating compiled applications
 written in the Java programming language

7.What is an adb ?
A. Android Debug Bridge, a command-line debugging application shipped
 with the SDK. It provides tools to browse the device, copy tools on
the device, and forward ports for debugging.

8.What is an Application ?
A.A collection of one or more activities, services,
listeners, and intent receivers. An application has a
 single manifest, and is compiled into a single .apk file on the device.

9.What is a Content Provider ?
A. A class built on ContentProvider that handles
 content query strings of a specific format to return data
in a specific format. See Reading and writing data to a content
 provider for information on using content providers.

10.What is a Dalvik ?
A. The name of Android’s virtual machine.
The Dalvik VM is an interpreter-only virtual machine that executes
 files in the Dalvik Executable (.dex) format, a format that is
optimized for efficient storage and memory-mappable execution.
 The virtual machine is register-based, and it can run classes compiled by a Java language compiler that have been transformed into its native format using the included “dx” tool. The VM runs on top of Posix-compliant operating systems, which it relies on for underlying functionality (such as threading and low level memory management). The Dalvik core class library is intended to provide a familiar development base for those used to programming with Java Standard Edition, but it is geared specifically to the needs of a small mobile device.

11.What is an DDMS?
A. Dalvik Debug Monitor Service, a GUI debugging application
 shipped with the SDK. It provides screen capture, log dump, and process
 examination capabilities.

12.What is Drawable?
A. A compiled visual resource that can be used as a background, title, or other part of the screen. It is compiled into an android.graphics.drawable subclass.

13.What is an Intent?
A. A class (Intent) that contains several fields describing what a caller would like to do. The caller sends this intent to Android’s intent resolver, which looks through the intent filters of all applications to find the activity most suited to handle this intent. Intent fields include the desired action, a category, a data string, the MIME type of the data, a handling class, and other restrictions.

14.What is an Intent Filter ?
A. Activities and intent receivers include one or more filters in their manifest to describe what kinds of intents or messages they can handle or want to receive. An intent filter lists a set of requirements, such as data type, action requested, and URI format, that the Intent or message must fulfill. For Activities, Android searches for the Activity with the most closely matching valid match between the Intent and the activity filter. For messages, Android will forward a message to all receivers with matching intent filters.

15.What is an Intent Receiver?
A. An application class that listens for messages broadcast by calling Context.broadcastIntent

16.What is a Layout resource?
A. An XML file that describes the layout of an Activity screen.

17.What is a Manifest ?
A. An XML file associated with each Application that describes the various activies, intent filters, services, and other items that it exposes.

18.What is a Resource ?
A. A user-supplied XML, bitmap, or other file, entered into an application build process, which can later be loaded from code. Android can accept resources of many types; see Resources for a full description. Application-defined resources should be stored in the res/ subfolders. 

19.What is a Service ?
A. A class that runs in the background to perform various persistent
 actions, such as playing music or monitoring network activity.

20.What is a Theme ?
A. A set of properties (text size, background color, and so on) bundled together to define various default display settings. Android provides a few standard themes, listed in R.style (starting with “Theme_”).

21.What is an URIs?
A. Android uses URI strings both for requesting data (e.g., a list of contacts) and for requesting actions (e.g., opening a Web page in a browser). Both are valid URI strings, but have different values. All requests for data must start with the string “content://”. Action strings are valid URIs that can be handled appropriately by applications on the device; for example, a URI starting with “http://” will be handled by the browser.

22.Can I write code for Android using C/C++?
A.Yes, but need to use NDK
Android applications are written using the Java programming language. Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.
                            Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included “dx” tool.

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

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

25.How is nine-patch image different from a regular bitmap?
A. 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.

26.What languages does Android support for application development?
A .Android applications are written using the Java programming language.

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

28.How will you record a phone call in Android? How to get a handle on Audio Stream for a call in Android?
A. Permissions.PROCESS_OUTGOING_CALLS: Allows an application to monitor, modify, or abort outgoing calls.

29.What’s the difference between file, class and activity in android?
A. File – It is a block of arbitrary information, or resource for storing information. It can be of any type.
Class – Its a compiled form of .Java file . Android finally used this .class files to produce an executable apk
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.

30.What is a Sticky Intent?
A. sendStickyBroadcast() performs a sendBroadcast (Intent) that is “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.

31.Does Android support the Bluetooth serial port profile?
A.Yes.

32.Can an application be started on powerup?
A.Yes.

33.How to Remove Desktop icons and Widgets ?
A. Press and Hold the icon or widget. The phone will vibrate and on
 the bottom of the phone you will see anoption 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

34.Describe a real time scenario where android can be used?
A. Imagine a situation that you are in a country where no one understands the language you speak and you can not read or write. However, you have mobile phone with you.
       With a mobile phone with 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.



35.How to Remove Desktop icons and Widgets?
A.  Press and Hold the icon or widget. The phone will vibrate and on the bottom of the phone you will see anoption 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

36.Describe a real time scenario where android can be used?
A. Imagine a situation that you are in a country where no one understands
 the language you speak and you can not read or write. However, you have
 mobile phone with you.

37.How to select more than one option from list in android xml file?
A.Give an example.
Specify android id, layout height and width as depicted in the following example.

38.What languages does Android support for application development?
A. Android applications are written using the Java programming language.

39.Describe Android Application Architectur ?
A. Android Application Architecture has the following components:

• Services – like N

• Intent – To perform inter-communetwork Operation

ication between activities or services

• Resource Externalization – such as strings and graphics

• Notification signaling users – light, sound, icon, notification, dialog etc

40.What is the Android Open Source Project?
A. We use the phrase “Android Open Source Project” or “AOSP” to refer to the people, the processes, and the source code that make up Android.

41.Why did we open the Android source code?
A. Google started the Android project in response to our own experiences launching mobile apps. We wanted to make sure that there would always be an open platform available for carriers, OEMs, and developers to use to make their innovative ideas a reality. We also wanted to make sure that there was no central point of failure, so that no single industry player could restrict or control the innovations of any other. The single most important goal of the Android Open-Source Project (AOSP) is to make sure that the open-source Android software is implemented as widely and compatibly as possible, to everyone’s benefit.

42.What kind of open-source project is Android?
A. Google oversees the development of the core Android open-source platform, and works to create robust developer and user communities. For the most part the Android source code is licensed under the permissive Apache Software License 2.0, rather than a “copyleft” license. The main reason for this is because our most important goal is widespread adoption of the software, and we believe that the ASL2.0 license best achieves that goal.

43.Why is Google in charge of Android?
A. Launching a software platform is complex. Openness is vital to the long-term success of a platform, since openness is required to attract investment from developers and ensure a level playing field. However, the platform itself must also be a compelling product to end users.

That’s why Google has committed the professional engineering resources necessary to ensure that Android is a fully competitive software platform. Google treats the Android project as a full-scale product development operation, and strikes the business deals necessary to make sure that great devices running Android actually make it to market.

By making sure that Android is a success with end users, we help ensure the vitality of Android as a platform, and as an open-source project. After all, who wants the source code to an unsuccessful product?

Google’s goal is to ensure a successful ecosystem around Android, but no one is required to participate, of course. We opened the Android source code so anyone can modify and distribute the software to meet their own needs.

44.What is Google’s overall strategy for Android product development?
A.We focus on releasing great devices into a competitive marketplace, and then incorporate the innovations and enhancements we made into the core platform, as the next version.

In practice, this means that the Android engineering team typically focuses on a small number of “flagship” devices, and develops the next version of the Android software to support those product launches. These flagship devices absorb much of the product risk and blaze a trail for the broad OEM community, who follow up with many more devices that take advantage of the new features. In this way, we make sure that the Android platform evolves according to the actual needs of real-world devices.

45.How is the Android software developed?
A. Each platform version of Android (such as 1.5, 1.6, and so on) has a corresponding branch in the open-source tree. At any given moment, the most recent such branch will be considered the “current stable” branch version. This current stable branch is the one that manufacturers port to their devices. This branch is kept suitable for release at all times.

Simultaneously, there is also a “current experimental” branch, which is where speculative contributions, such as large next-generation features, are developed. Bug fixes and other contributions can be included in the current stable branch from the experimental branch as appropriate.

Finally, Google works on the next version of the Android platform in tandem with developing a flagship device. This branch pulls in changes from the experimental and stable branches as appropriate.

46.Why are parts of Android developed in private?
A.It typically takes over a year to bring a device to market, but of course device manufacturers want to ship the latest software they can. Developers, meanwhile, don’t want to have to constantly track new versions of the platform when writing apps. Both groups experience a tension between shipping products, and not wanting to fall behind.

To address this, some parts of the next version of Android including the core platform APIs are developed in a private branch. These APIs constitute the next version of Android. Our aim is to focus attention on the current stable version of the Android source code, while we create the next version of the platform as driven by flagship Android devices. This allows developers and OEMs to focus on a single version without having to track unfinished future work just to keep up. Other parts of the Android system that aren’t related to application compatibility are developed in the open, however. It’s our intention to move more of these parts to open development over time.

47.When are source code releases made?
A.When they are ready. Some parts of Android are developed in the open, so that source code is always available. Other parts are developed first in a private tree, and that source code is released when the next platform version is ready.

In some releases, core platform APIs will be ready far enough in advance that we can push the source code out for an early look in advance of the device’s release; however in others, this isn’t possible. In all cases, we release the platform source when we feel the version has stabilized enough, and when the development process permits. Releasing the source code is a fairly complex process.

48.What is involved in releasing the source code for a new Android version?
A.Releasing the source code for a new version of the Android platform is a significant process. First, the software gets built into a system image for a device, and put through various forms of certification, including government regulatory certification for the regions the phones will be deployed. It also goes through operator testing. This is an important phase of the process, since it helps shake out a lot of software bugs.

 Once the release is approved by the regulators and operators, the manufacturer begins mass producing devices, and we turn to releasing the source code.

Simultaneous to mass production the Google team kicks off several efforts to prepare the open source release. These efforts include final API changes and documentation (to reflect any changes that were made during qualification testing, for example), preparing an SDK for the new version, and launching the platform compatibility information.

Also included is a final legal sign-off to release the code into open source. Just as open source contributors are required to sign a Contributors License Agreement attesting to their IP ownership of their contribution, Google too must verify that it is clear to make contributions.

Starting at the time mass production begins, the software release process usually takes around a month, which often roughly places source code releases around the same time that the devices reach users.


Wednesday 13 November 2013

Remove Special characters and invalid characters from in Phonegap with Android and Javascript

Html Part:

<body>
<form>
<textarea id="code"></textarea>
<input type="button" value="OK" onclick="convertString()"/>
</form>
</body>

Script Part:

<script>
function convertString()
{
    var phrase = document.getElementById('code').value;
        alert(phrase);
         var maxLength = 100;

        var returnString = phrase.toLowerCase();
        //Convert Characters
        returnString = returnString.replace(/ö/g, 'o');
        returnString = returnString.replace(/ç/g, 'c');
        returnString = returnString.replace(/ÅŸ/g, 's');
        returnString = returnString.replace(/ı/g, 'i');
        returnString = returnString.replace(/ÄŸ/g, 'g');
        returnString = returnString.replace(/ü/g, 'u'); 

        // if there are other invalid chars, convert them into blank spaces
        returnString = returnString.replace(/[^a-z0-9\s-]/g, "");
        // convert multiple spaces and hyphens into one space      
        returnString = returnString.replace(/[\s-]+/g, " ");
        // trims current string
        returnString = returnString.replace(/^\s+|\s+$/g,"");
        // cuts string (if too long)
        if(returnString.length > maxLength)
        returnString = returnString.substring(0,maxLength);
        // add hyphens
        returnString = returnString.replace(/\s/g, "-"); 
       
        alert(returnString);
}
</script>

Monday 11 November 2013

How to install phoneGap for Android using Windows and Eclipse

       PhoneGap     

       PhoneGap is a mobile development framework that allows developers to build applications for a variety of mobile platforms, using familiar web technologies such as HTML, CSS, and JavaScript.

 PhoneGap Supported Platforms:

     1. IOS
     2. Android
    3. BlackBerry
    4. Windows 8 

To create android project with phonegap: Click Here

Extract Source code from APK File



Step 1:
Make a new folder and put .apk file (which you want to decode) now rename this .apk file with extension .zip (eg:rename from filename.apk to filename.apk.zip) and save it..now you get classes.dex files etc...at this stage you are able to see drawable but not xml and java file...so cont...
Step 2:
Now extract this zip apk file in the same folder(in this eg or case NEW FOLDER). now dowmload dex2jar from this link http://code.google.com/p/dex2jar/ and extract it to the same folder (in this case NEW FOLDER).....now open command prompt and reach to that folder (in this case NEW FOLDER)....after reaching write dex2jar classes.dex and press enter.....now you get classes.dex.dex2jar file in the same folder......now download java decompiler from http://java.decompiler.free.fr/?q=jdgui and now double click on jd-gui and click on open file then open classes.dex.dex2jar file from that folder...now you get class file...save all these class file (click on file then click "save all sources" in jd-gui)..by src name....at this stage you get source...but xml files are still unreadable...so cont...
Step 3:
Now open another new folder and put these files
1.    put .apk file which you want to decode
2.    download apktool v1.x AND apktool install window using google and put in the same folder
3.    download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)
4.    Open a command window
5.    Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
6.    apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.
Step 4:
It's not any step just copy contents of both folder(in this case both new folder)to the single one
and now enjoy with source code...

Animation sample program in Android


This sample android program shows you how to do simple animation in Android. In this program the xml file ani.xml is used to rotate the images in sequence. The images must be copied to the /res/drawable folder together with the ani.xml file.
The FrameAnimation1.java file is as follows:
package com.javasamples.ani;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class FrameAnimation1 extends Activity {
 Button b;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  this.setupButton();
 }

 private void setupButton() {
  b = (Button) this.findViewById(R.id.startFAButtonId);
  b.setOnClickListener(new Button.OnClickListener() {
   public void onClick(View v) {
    parentButtonClicked(v);
   }
  });
 }

 private void parentButtonClicked(View v) {
  animate();
 }

 private void animate() {
  ImageView imgView = (ImageView) findViewById(R.id.animationImage);
  // imgView.setVisibility(ImageView.VISIBLE);
  imgView.setBackgroundResource(R.drawable.ani);

  AnimationDrawable frameAnimation = (AnimationDrawable) imgView
    .getBackground();

  if (frameAnimation.isRunning()) {
   frameAnimation.stop();
   b.setText("Start");
  } else {
   frameAnimation.start();
   b.setText("Stop");
  }
 }
}