【发布时间】:2015-08-03 14:34:46
【问题描述】:
我正在尝试编写一个应用程序,您可以在其中输入地址,然后将您重定向到谷歌地图。 (我想这叫做隐式意图)
-我已经创建了启动主要活动的意图,这是我的应用程序中唯一的活动。 Main 活动由一些文本、一个编辑字段和一个按钮组成。
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>
这是按钮的代码:
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
}
}
【问题讨论】:
-
您确定您的设备上安装了谷歌地图吗?
-
设备是模拟器,我必须这样做吗?