Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Tuesday, January 3, 2012

How to Disable Back button in android


/**
* To disable back button(when click back button nothing happen)
*/
@Override
public void onBackPressed() {
  return;
}

How to Launch Activities from different application in android



For Example We have two application with same package and Different Namespace.
First Application: Com.Example.Application1
Second Application: Com.Example.Application2
In this case you can define common Manifest file for both Application1 and Application2 as given below
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="Com.Example">
And add given line to your manifest file
<activity android:name=".Application2/Activity2">
  <intent-filter>
    <action android:name="Application2.intent.action.Launch" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>
Now you can create an Intent to launch Activity2 from the Activity1 with this line of code:
Intent intent = new Intent("Application2.intent.action.Launch");
startActivity(intent);


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);
      }
    });
}
}