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
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…