5

私はあなたがアドレスを入力することができるアプリを書こうとしています、そしてあなたはグーグルマップにリダイレクトされます。(これは暗黙の意図と呼ばれていると思います)

-アプリ内の唯一のアクティビティであるメインアクティビティを起動するインテントを作成しました。メインアクティビティは、テキスト、編集フィールド、ボタンで構成されています。

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

    }

}
4

1 に答える 1

5

これをエミュレーターでテストしている場合は、デバイスの場合とは異なります。

Android仮想デバイスを作成するときは、ターゲットとしてGoogleAPIを選択する必要があります。インストールされていない場合は、SDKManagerを使用してダウンロードできます。

これを見てください。

ここに画像の説明を入力してください

于 2012-07-17T17:54:48.500 に答える