Create Intent to open a Uri : Intent « Core Class « Android






Create Intent to open a Uri

    
package app.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Test extends Activity {
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    final AlertDialog.Builder adb = new AlertDialog.Builder(this);
    final EditText addressfield = (EditText) findViewById(R.id.address);
    final Button button = (Button) findViewById(R.id.launchmap);
    button.setOnClickListener(new Button.OnClickListener() {
      public void onClick(View v) {
        try {
          // Perform action on click
          String address = addressfield.getText().toString();
          address = address.replace(' ', '+');
          Intent geoIntent = new Intent(
              android.content.Intent.ACTION_VIEW, Uri
                  .parse("geo:0,0?q=" + address));
          startActivity(geoIntent);
        } catch (Exception e) {
          AlertDialog ad = adb.create();
          ad.setMessage("Failed to Launch");
          ad.show();

        }
      }
    });

  }
}

//main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Please enter your home address."
    />
<EditText
  android:id="@+id/address"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
  android:autoText="true"
  />
<Button
  android:id="@+id/launchmap"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:text="Show Map"
    /> 
<TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Unlocking Android"
    />
</LinearLayout>

   
    
    
    
  








Related examples in the same category

1.Using Intent to open other Activity
2.extends IntentService
3.Phone Intent
4.Map Intent
5.Market Intent
6.Load Activity with Intent
7.Using Intent to make another phone call
8.extends IntentService to create your own Intent
9.Adding data bundle to Intent
10.Using Intent to show other Activities
11.Start Intent with Utility class
12.Load library Activity with Intent
13.Capture Image with Intent
14.Intent.ACTION_MEDIA_MOUNTED
15.Using Intent to record audio
16.Video Player Intent
17.Video Capture Intent
18.Implementing an application service that will run in response to an alarm, allowing us to move long duration work out of an intent receiver.
19.Example of various Intent flags to modify the activity stack.
20.Sample code that invokes the speech recognition intent API.
21.extends IntentService to upload a file
22.factory class for generating various intents
23.Open Web Page Intent
24.Is Intent Available
25.start MMS Intent
26.Access the Internet
27.Pdf viewer
28.Rotation One Demo
29.Media activity