Friday, December 9, 2011

how to use android emulator to find the gps location.

Usually from your emulator you can't get current location when you run your GPS location finder application. 
First you have to make sure  this line of code is available in your source code.
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
You can also request location updates from both the GPS and the Network Location Provider by calling requestLocationUpdates() twice—once for NETWORK_PROVIDER and once for GPS_PROVIDER. But when you run the applicatin in emulator, you should use GPS provider to obtain your location.
And now you have to move to below location by yourself. And run the ddms.bat file
C:/android sdk/tools/ddms.bat
When you run this bat file you will find an emulator controller tab there. from this tab you can pass locations to emulator by longitude and latitude of your current location.

Here you can find your location's longitude and latitude.

Difference between GPS and Android's Network Location Provider to acquire the user location

Obtaining User Location in android application using GPS or Network Location Provider

GPS
Android's Network Location Provider
Although GPS is most accurate
Android's Network Location Provider determines user location using cell tower and Wi-Fi signals
It only works outdoors
Providing location information in a way that works indoors and outdoors
It quickly consumes battery power

Uses less battery power
It doesn’t return the location as quickly as users want.
Responds faster


Note: To obtain the user location in your application, you can use both GPS and the Network Location Provider, or just one.

Thursday, December 8, 2011

How to redirect to another window in android when button click

This Sample Code explain how to show another window of given url when button click in android.

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainWindowActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button)findViewById(R.id.button1);    

    button.setOnClickListener(new OnClickListener() {
      public void onClick(View arg) {
        Intent viewIntent =
          new Intent("android.intent.action.VIEW",
            Uri.parse("https://google.com"));
          startActivity(viewIntent);
      }
    });
}
}