5

I am trying to write an app where you can type in an address and then you get redirected to google maps. (I suppose this is called implicit intent)

-I have created an intent to launch the main activity, which is the only activity in my app. The Main activity consists of some text, an editfield and a button.

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.where_do_you_live"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />

</manifest>

this is the code for the button:

public void Button1Click(View view)
{       
    try
    {
        addressField=(EditText)findViewById(R.id.address);

        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)
    {
        TextView tv=(TextView)findViewById(R.id.textView1);
        tv.setText(e.toString());
        //finding stuff

    }

}
4

1 回答 1

5

如果您在模拟器中对此进行测试,则情况与在设备中不同。

创建 Android 虚拟设备时,应选择 Google API 作为目标。如果您没有安装它们,您可以使用 SDK Manager 下载它。

看看这个

在此处输入图像描述

于 2012-07-17T17:54:48.500 回答