Friday, July 30, 2010

Android Market on Android emultor

Finally, I am able to run the Android Market on the emulator. And also, see all the paid apps and copy-protected app, right here on my emulator.

What do you need?

Well, the basic SDK. 1.5, 1.6 or 1.1

And then, go to the HTC website where you can find the images/recovery images. Download the version (system image only) which you want to run.

http://developer.htc.com/google-io-device.html#s3
(Download the System Image zip)

Extract the files of this zip. There's a system.img file which you will need in the next steps.

Create an AVD (1.1, 1.5 or 1.6) depending on your requirements.

Copy this system.img file into the avd directory. For example, if you created an avd named "MyPhone", go to .avd\MyPhone\ and paste this system.img file here.

Now start the emulator. Voila, You are ready to go. After you sign in with a google account, your phone is ready to use. You now have access to all the market apps right from your emulator.

Note: If you are not able to run it successfully, and if you are getting Network communication error, please download the AVD that I have created from this link.

http://developer.htc.com/adp.html

Thursday, July 29, 2010

Passing information between Activities

Hi

There are serveral methods for passing information between Activities. But its not only the method that takes us to better results but also it depends on our ability to choose the optimized method out of available options.

1. Shared Prefs
2. Internal Storage
3. External Storage
4. SQLite Databases
5. Network Connection
6. Stuffing intent Object

So main point of concern here is Stuffing intent object.

Let's say we 've an Activity A that starts Activity B. In activity A before starting Activity B using intent object , first we will stuff the intent object which desired information that activity A needs to send to activity B.

public class ActivityA extends Activity{
....

Intent i = new Intent(A.this,B.class);

i.put("[name of variable]",[default value for variable]);

// eg. i.put("type","1");


startActivity(i);

}

Now in Activity B

public class ActivityB extends Activity {

....

Intent i = getIntent();

i.get..... methods can be used to get the desired values keeping the types of values in mind before storing them in variables.



}

Why Android Will Win the Mobile Platform War

Mirror, mirror, on the wall, which mobile operating system is fairest of all? That's a common question, given the many contenders in the mobile arena--and the well-publicized glitches that have recently come up.

Due to wide spread availability of android devices and its features android is gonna lead smartphones markets around the globe.

Few of its several features are

1. Flexibility

A hallmark of Apple's approach has always been putting users in a "walled garden" whereby they are "protected" from having to deal with the computer's nuts and bolts directly. Hand-in-hand with that approach comes restrictiveness; users are only allowed to do things that Apple has decided to let them do, just as they can only buy applications that have been preapproved. Apple insists on controlling the whole ecosystem.

With Android, on the other hand--much as with Linux itself--it's a wide-open world. Users have much more freedom to do what they want, developers have more freedom to create and sell applications for the ecosystem, and manufacturers can customize the experience for their customers.

2. Strength in Numbers

Apple's ability to be so restrictive stems largely from the fact that there's just one Apple and just one iPhone. That device could be the best in the world, but if there's only one, consumers will inevitably get less control and less choice. You may recall seeing something like that in the desktop arena.

With Android, the choices are many. LG alone is set to roll out at least 20 new Android devices this year. Among other things, that means that if one device fails, there will be plenty of others to continue the race.

3. DIY Tools

With App Inventor, Google has put even more power in users' hands by making it easier than ever before to create the apps they want. Sure, that will result in more junk apps out there--but it will also surely enable some gems. This will be just what the platform needed to help it catch up with the iPhone's head start in the app arena. A year ago, there were some 10,000 apps in Android Market--this month, it's expected to surpass 100,000. Where the apps go, users will follow.

4. Focus on Users

One of the things I found most disturbing in the recent "Antennagate" debacle surrounding Apple's iPhone 4 is how long the company took to acknowledge the problem and to respond. I think this ties directly into its iron-fisted control and monopoly over the iPhone experience. Monopoly-holders don't tend to care much about users; only when there's choice do they become a concern.

5. The Google Factor

Yes, there are other Linux-based mobile operating systems out there--Intel's MeeGo and Samsung's Bada, for instance. But Android is the one that has Google's support, and that's worth a lot.

Then, of course, there's the data. By virtually every account, Android looks poised to dominate the smartphone market in not very long. Some 100,000 Android devices are shipping every day, and market researcher ABI predicts that Linux-based handsets will account for 33 percent of the market by 2015.

Android specifically, meanwhile, is growing quickly. Whereas Apple smartphones lost a percentage point of market share between February and May, Google's Android gained an additional 4 percent, according to comScore. That's pretty impressive.

Heck, even Facebook's Mark Zuckerberg recently ditched his iPhone for an Android device.

In short, while Apple will always have its die-hard fans, just as it does on the desktop, the days of its restrictive dominance are numbered, at least in the mobile arena. Instead, a common sentiment in the coming months, I predict, will be the one depicted on this T-shirt. (No offense, Steve!)

Streaming a Video file

Good morning

Here's a simple code to play a 3gp Video file from network stream. But before going ahead you need to make sure that you have an actual GPRS enabled device and you have given Internet permission to your android application.

package com.playweb;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class PlayWeb extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//String url = "rtsp://192.168.1.2/vod/DES.3gp";
String url = "rtsp://v5.cache4.c.youtube.com/CkELENy73wIaOAliq6nKYdHZZxMYESARFEIJbXYtZ29vZ2xlSARSBWluZGV4Wgl4bF9ibGF6ZXJg7sXyzsWH3ZlMDA==/0/0/0/video.3gp";

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
}

I can also play the same using the MediaController class and its display and holder. But I was unable to make out the difference between them. So this time I 'm gonna ask this question to android public forums and when I will get the answer I will let you know.

The code for playing video using MediaController


package com.torrins;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;


public class PlayVideo1 extends Activity implements
OnBufferingUpdateListener, OnCompletionListener,
OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {

private static final String TAG = "MediaPlayerDemo";
private int mVideoWidth;
private int mVideoHeight;
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path;
private Bundle extras;
private static final String MEDIA = "media";
private static final int LOCAL_AUDIO = 1;
private static final int STREAM_AUDIO = 2;
private static final int RESOURCES_AUDIO = 3;
private static final int LOCAL_VIDEO = 4;
private static final int STREAM_VIDEO = 5;
private boolean mIsVideoSizeKnown = false;
private boolean mIsVideoReadyToBePlayed = false;

/**
*
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.mediaplayer_2);
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();

}

private void playVideo(Integer Media) {
String destinationDir;
String url;
doCleanUp();
try {

switch (Media) {
case LOCAL_VIDEO:
/*
* TODO: Set the path variable to a local media file path.
*/
path = "";
if (path == "") {
// Tell the user to provide a media file URL.
Toast
.makeText(
PlayVideo1.this,
"Please edit MediaPlayerDemo_Video Activity, "
+ "and set the path variable to your media file path."
+ " Your media file must be stored on sdcard.",
Toast.LENGTH_LONG).show();

}
break;
case STREAM_VIDEO:
destinationDir = "/vod/mp4:Extremists.mp4";
url = "rtsp://v5.cache4.c.youtube.com/CkELENy73wIaOAliq6nKYdHZZxMYESARFEIJbXYtZ29vZ2xlSARSBWluZGV4Wgl4bF9ibGF6ZXJg7sXyzsWH3ZlMDA==/0/0/0/video.3gp";
Log.v(TAG,url);
path = url;
if (path == "") {
// Tell the user to provide a media file URL.
Toast
.makeText(
PlayVideo1.this,
"Please edit MediaPlayerDemo_Video Activity,"
+ " and set the path variable to your media file URL.",
Toast.LENGTH_LONG).show();

}

break;


}

// Create a new media player and set the listeners
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(path);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);


} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
}
}

public void onBufferingUpdate(MediaPlayer arg0, int percent) {
Log.d(TAG, "onBufferingUpdate percent:" + percent);

}

public void onCompletion(MediaPlayer arg0) {
Log.d(TAG, "onCompletion called");
}

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.v(TAG, "onVideoSizeChanged called");
if (width == 0 || height == 0) {
Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
return;
}
mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
//if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
//}
}

public void onPrepared(MediaPlayer mediaplayer) {
Log.d(TAG, "onPrepared called");
mIsVideoReadyToBePlayed = true;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}

public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
Log.d(TAG, "surfaceChanged called");

}

public void surfaceDestroyed(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceDestroyed called");
}


public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo(5);


}

@Override
protected void onPause() {
super.onPause();
releaseMediaPlayer();
doCleanUp();
}

@Override
protected void onDestroy() {
super.onDestroy();
releaseMediaPlayer();
doCleanUp();
}

private void releaseMediaPlayer() {
if (mMediaPlayer != null) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}

private void doCleanUp() {
mVideoWidth = 0;
mVideoHeight = 0;
mIsVideoReadyToBePlayed = false;
mIsVideoSizeKnown = false;
}

private void startVideoPlayback() {
Log.v(TAG, "startVideoPlayback");
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
}




Thanks

Thursday, July 22, 2010

Android System architecture : Episode 1

Android Software Stack has a very simple system architecture

Linux Kernel 2.6
Libraries and Android Runtime
Application Framework
Applications

Lets break it one by one:::::


Linux Kernel 2.6


Its hardware abstraction layer. It provides support to access device hardware and capabilities.

Display drivers
Camera drivers
Bluetooth drivers
Binder (IPC) drivers
USB drivers
Keyboard driver
Wifi driver
M - Systems driver
Audio driver
Power Management

Libraries
These are the libraries written in C languages.
Surface Manager
Open GL/ES : 3D rendering engine
SGL : 2D rendering engine
Media Framework
Free type : renders fonts
SSL : secured socket layer
SQLite
WebKit - browser
LibC

Android Run time

Core Libraries : written in Java Programming Languages
Dalvik Virtual Machine


Application Framework


Activity Manager
Package Manager
Window Manager
Telephony Manager
Content Providers
Resource Manager
View Systems
Location Manager
Notification Manager
XMPP Services

Sunday, July 18, 2010

Aankhen

Aankhen First Version Launched
Aankhen is a fun application that engages its users by giving them challenging images. User has to recognize the image so as to score more. On the completion of each stage user can view his score and the user can choose to move to more challenging level. Experienced users can increase the challenge level through application settings.

Saturday, July 17, 2010

Momo 10 Meet up at One 97

Hi

Good evening !

Recently I visited the Momo Meetup at One 97 Communications in Noida. As a mobile application developer I came to know that its the social networking application that are leading the mobile applications. There were 5 products that were presented by various members like (Samsung, Spice Digital, Mig33, Peek , rocketalk) out of which 4 were social networking applications giving there users an ability to connect with other friends and share their network updates on popular social networking platforms like facebook, orkut and twitter. I liked the idea behind the m.cell.in to get updates from all popular social networking sites like Facebook, twitter and orkut from a single application.


Then there was one innovative product by samsung called bada. a mobile platform that could develop the application for the features phones. It's a free SDK and open to developer. I 'm gonna download it today. Everything went well , from starting introduction to panel discussion Q & A sessions at the end.


Three persons also won a prizes as Samsung Wave handset for answering right questions posed in a quiz organized by Samsung.

Thanks to organizers and all members of Momo 10 meet up!