How to Install .apk file in Emulator

Step – 1

Go to cmd.

Step – 2

Then locate to the plateform-tools (e.g. Program Files \ Android \ android-sdk \ plateform-tools )

Step – 3

Install the apk. If your .apk file located at D directory, then the command should be like this,

e.g : C:\Program Files \ Android \ android-sdk \ plateform-tools > adb install D:\Paint.apk

then press enter.

Out Put :

133 KB/s (1338340 bytes in 9.802s)
pkg: /data/local/tmp/Paint.apk
Success

Know Issue,

error: device not found
– waiting for device –

Solution

1. Start your AVD (Android Virtual Device)

2. C:\Program Files (x86)\Android\android-sdk\platform-tools>adb kill-server

3. C:\Program Files (x86)\Android\android-sdk\platform-tools>adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *

4. Now go to the step – 3

 

Thank you !!!! Wait for next post

 

Android Sudoku – 7 Adding a Menu

Basically Android supports two type of menus

1. Menu for press physical Menu button

2. Context menu that pop-up when you press and hold the finger on the screen.

Now we discuss about first menu type.

STEP – 1 First we need to define strings at /res/values/strings.xml

<string name=”settings_label”>Settings…</string>
<string name=”settings_title”>Sudoku settings</string>
<string name=”settings_shortcut”>s</string>
<string name=”music_title”>Music</string>
<string name=”music_summary”>Play background music</string>
<string name=”hints_title”>Hints</string>
<string name=”hints_summary”>Show hints during play</string>

STEP – 2 Define the menu using XML at /res/menu/menu.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<menu xmlns:android=”http://schemas.android.com/apk/res/android”&gt;
<item android:id=”@+id/settings”
android:title=”@string/settings_label”
android:alphabeticShortcut=”@string/settings_shortcut” />
</menu>

STEP – 3 Modify the SudokuQuiz class to bring the menu

Add these imports at /src/androidsl.raaz.sudoku/SudokuQuizActivity.java ,

import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

Then we override the Sudoku.onCreateOptionsMenu( ) method /src/androidsl.raaz.sudoku/SudokuQuizActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}

getMenuInflater( ) returns an instance of MenuInflater that we use to read the menu definition from XML and turns it into a real view. When the user selects any menu item, onOptionsItemSelected( ) will be called. Here’s the definition for that method: /src/androidsl.raaz.sudoku/SudokuQuizActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.settings:
startActivity(new Intent(this, Prefs.class));
return true;
// More items go here (if any) …
}
return false;
}

Restaurant – Create a Simple Form – 2

Step – 1

We already create the new Project in our previous tutorials.

Step – 2 Modify the Layout

Open the file called main.xml at Restaurant/res/layout/main.xml, and change the code as in below.

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<LinearLayout
android:orientation=”horizontal”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
>
<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Name:”
/>
<EditText android:id=”@+id/name”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
/>
</LinearLayout>
<LinearLayout
android:orientation=”horizontal”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
>
<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Address:”
/>
<EditText android:id=”@+id/addr”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
/>
</LinearLayout>
<Button android:id=”@+id/save”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Save”
/>
</LinearLayout>

This gives us a three-row form: one row with a labeled field for the restaurant name, one with a labeled field for the restaurant address, and a big Save button.

Step – 3 Support All Screen Sizes

We may want to test this application on an emulator, phone,  or tablet. So we need tho change our AndroidManifest to fit the all screen sizes. Open Restaurant/AndroidManifest.xml and add this code.

<supports-screens
android:xlargeScreens=”true”
android:largeScreens=”true”
android:normalScreens=”true”
android:smallScreens=”false”
/>

Step – 4 Run the Application

This will give the following output.

Step – 5 Create a Model Class

Now, we want to add a class to the project that will hold onto individual restaurants that will appear in the Restaurant List.. Right now, we can only really work with one restaurant, but that will change in a future tutorial. So create the RestaurantList.java class at Restaurant/src/apt/RstaurantList.java with following codes.

package androidsl.com;

public class RestaurantList {

    private String name=””;
    private String address=””;
    public String getName() {
    return(name);
    }
    public void setName(String name) {
    this.name=name;
    }
    public String getAddress() {
    return(address);
    }
    public void setAddress(String address) {
    this.address=address;
    }

}
This is simply a rudimentary model, with private data members for the name and address, and getters and setters for each of those.

Step –  6 Save the Form to the Model

Finally, we want to hook up the Save button, such that when it is pressed, we update a restaurant object based on the two EditText fields. T o do this, open up the Restaurant/src/apt/RestaurantActivity.java file and replace the generated Activity implementation with the one shown below.

package androidsl.com;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class RestaurantActivity extends Activity {
    /** Called when the activity is first created. */

    RestaurantList r=new RestaurantList();
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button save=(Button)findViewById(R.id.save);
    save.setOnClickListener(onSave);
    }

    private View.OnClickListener onSave=new View.OnClickListener() {
    public void onClick(View v) {
    EditText name=(EditText)findViewById(R.id.name);
    EditText address=(EditText)findViewById(R.id.addr);
    r.setName(name.getText().toString());
    r.setAddress(address.getText().toString());
    }
    };
}

What we did so far,

** Create a single local restaurant instance when the activity is instantiated

** Get our Button from the Activity via findViewById(), then connect it to a listener to be notified when the button is clicked

** In the listener, we get our two EditText widgets via findViewById(), then retrieve their contents and put them in the restaurant

This code sample shows the use of an anonymous inner class implementation of a View.OnClickListener, named onSave. This technique is used in many places throughout this book, as it is a convenient way to organize bits of custom code that go into these various listener objects.

Playing audio & video in Android – 1

Android’s open platform and provider-agnostic philosophy ensures that it offers a multimedia API capable of playing and recording a wide range of image, audio, and video formats, both locally and streamed. The Camera API and OpenCORE multimedia platform expose these capabilities to your applications, providing comprehensive multimedia functionality.

Android includes a comprehensive Media Player to simplify the playback of audio and video. This section describes how to use it to control and manipulate media playback within your applications. Android 2.1 (API level 7) supports the following multimedia formats for playback as part of the base framework. Note that some devices may support playback of additional file formats:

Audio
➤ AAC LC/LTP
➤ HE-AACv1 (AAC+)
➤ HE-AACv2 (Enhanced AAC+)
➤ AMR-NB
➤ AMR-WB
➤ MP3
➤ MIDI
➤ Ogg Vorbis
➤ PCM / WAVE

Video
➤ H.263
➤ H.264 AVC
➤ MPEG-4 SP

Android Sudoku – 6 Applying a Theme for About

A theme is a collection of styles that override the look and feel of Android widgets. Subjects were drawn from the Cascading Style Sheets (CSS) used web page, which separates content and presentation screen or style.  Android comes with several themes that can be reference by name, four, or you can make your own theme by subclassing existing and ignore their default values.

To use the theme, open the AndroidManifest.xml and change the About activity with following code.

<activity android:name=”.About” android:label=”@string/about_title” android:theme=”@android:style/Theme.Dialog” >
</activity>

The android @: prefix before the name of style means that this is a reference to a resource defined by Android, not one that is defined in its the program. Run again and the output look at like this,

Android Sudoku – 5

Implementing an About Box

When the user select the About button (touch or navigate with D-pad or traceball and press the selection button), we want to pop up a window with some information. After scrolling through the text, the user can press the Back button to dismiss the window.

We can accomplish this in several ways,

1.Define a new Activity, and start it

2. Use the AlertDialog class, and show it

3. Subclass   Android`s Dialog class, and show that

For this application, let`s define a new activity. Like the main Sudoku activity.

STEP 1. : Now we need About activity layout file. We will name it res/layout/about.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<ScrollView
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:padding=”10dip” >
<TextView
android:id=”@+id/about_content”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/about_text”/>
</ScrollView>

We need only one version of layout, because this will work both portrait and landscape modes.

STEP 2 : Add strings for the title of the About dialog box and the text it contains to res/values/strings.xml

<string name=”about_title”>About Android Sudoku</string>
<string name=”about_text”> Sudoku is a logic-based number placement puzzle. Starting with a partially completed 9×9 grid, the objective is to fill the grid so that each row, each column, and each of the 3×3 boxes (also called <i>blocks</i>) contains the digits 1 to 9 exactly once.
</string>

– is used to prevents an extra blank from appearing before the first word.

STEP : 3 Define the About activity at About.java . Create new java class at /src/androidsl.raaz.sudoku/Activity.java

package androidsl.raaz.sudoku;

import android.app.Activity;
import android.os.Bundle;

public class About extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);
    }
    }

STEP 4 : Wire all this up to the About button in the SudokuQuiz class /src/androidsl.raaz.sudoku/SudokuQuizActivity.java

1. Add few imports

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;

2. In the onCreate( ) method, add code to call findViewById( ) to look up an Android view given its resource ID, and add code to call setOnClickListener() to tell Android which object to tickle when the user touches or clicks the view:

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set up click listeners for all the buttons
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
}

3. The setOnClickListener( ) method needs to be passed an object that implements the OnClickListener Java interface. We’re passing it the this variable, so we had better make the current class (Sudoku) implement that interface, or we’ll get a compiler error. OnClickListener has one method in it called onClick( ), so we have to add that method to our class as well. [If you’re a Java expert, you may be wondering why we didn’t use an anonymous inner class to handle the clicks. You could, but according to the Android developers, every new inner class takes up an extra 1KB of memory.]

/src/androidsl.raaz.sudoku/SudokuQuizActivity.java

public class Sudoku extends Activity implements OnClickListener {
// …
public void onClick(View v) {
switch (v.getId()) {
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
// More buttons go here (if any) …
}
}
}

To start an activity in Android, we first need to create an instance of the Intent class. There are two kinds of intents:

(a) public (named) intents that are registered with the system and can be called from any application
(b) private (anonymous) intents that are used within a single application.

For here when we run this program and select About button this will get an error.

Solution : We forgot one important step: every activity needs to be declared in AndroidManifest.xml. To do that, double-click the file to open it, switch to XML mode if necessary by selecting the AndroidManifest.xml tab at the bottom, and add a new <activity> tag after the closing tag of the first one

<activity android:name=”.About” android:label=”@string/about_title” >
</activity>

Now run again and press About button, this will give the following screen.

Android SDK Features

The true appeal of Android as a development environment lies in the APIs it provides. As an application-neutral platform, Android gives you the opportunity to create applications that are as much a part of the phone as anything provided out of the box. The following list highlights some of the most noteworthy Android features:

  • No Licensing, distribution or development fees.
  • No fee for release approval process
  • Full control of multimedia, including playback and recording with the camera and microphone.
  • Wi-Fi access
  • GSM, EDGE, 3G, SMS, Call, etc services
  • Comprehensive APIs for location-based services – GPS
  • APIs for using sensor hardware, including accelerometers and the compass
  • Libraries for using Bluetooth for peer-to-peer data transfer
  • IPC message passing
  • Shared data stores
  • Background applications and processes
  • Home-screen Widgets, Live Folders, and LiveWallpaper
  • The ability to integrate application search results into the system search
  • An integrated open-source HTML5WebKit-based browser
  • Full support for applications that integrate map controls as part of their user interface
  • Mobile-optimized hardware-accelerated graphics, including a path-based 2D graphics library and support for 3D graphics using OpenGL ES 2.0
  • Media libraries for playing and recording a variety of audio/video or still image formats
  • Localization through a dynamic resource framework
  • An application framework 
  • that encourages reuse of application components and the replacement of native applications

Android Sensors – 1 Introduction

Modern mobile phones are much more than simple communication devices with a connection to the Internet. With microphones, cameras, accelerometers, compasses, temperature gauges, and brightness detectors, smart-phones have become extra-sensory devices which able to augment your own perception.

Sensors that detect physical and environmental properties offer an exciting innovation for enhancing the user experience of mobile applications. The incorporation of electronic compasses, gravity sensors, brightness gauges, and proximity sensors in modern devices provides an array of new possibilities for interacting with devices, such as augmented reality and physical movement-based input.

–Will be Continue —

Android Sudoku – 4

Using Alternate Resources

Create the new file in res/layout-land/main.xml with following codes.

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:background=”@color/background”
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”
android:padding=”15dip”
android:orientation=”horizontal” >
<LinearLayout
android:orientation=”vertical”
android:layout_height=”wrap_content”
android:layout_width=”fill_parent”
android:layout_gravity=”center”
android:paddingLeft=”20dip”
android:paddingRight=”20dip” >
<TextView
android:text=”@string/main_title”
android:layout_height=”wrap_content”
android:layout_width=”wrap_content”
android:layout_gravity=”center”
android:layout_marginBottom=”20dip”
android:textSize=”24.5sp” />
<TableLayout
android:layout_height=”wrap_content”
android:layout_width=”wrap_content”
android:layout_gravity=”center”
android:stretchColumns=”*” >
<TableRow>
<Button
android:id=”@+id/continue_button”
android:text=”@string/continue_label” />
<Button
android:id=”@+id/new_button”
android:text=”@string/new_game_label” />
</TableRow>
<TableRow>
<Button
android:id=”@+id/about_button”
android:text=”@string/about_label” />
<Button
android:id=”@+id/exit_button”
android:text=”@string/exit_label” />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>

This will give the following Output….