android之通过intent跳转到地图项

来源:互联网 发布:360数据恢复大师好用吗 编辑:程序博客网 时间:2024/06/06 11:04

首先:对main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".ActivityMain" >
<!--
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
-->
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="show the map!!!"
        />
    
    <!-- 需注意 -->
    <com.google.android.maps.MapView
        android:id="@+id/myMapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        android:apiKey="c4579586f41a90372f762cb65c78be5d"
        />
    
    
    
</LinearLayout>


对ActivityMain.java  注意直接继承的类

package com.myexample.intent0409;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.android.maps.MapActivity;

//找到这个合适的继承关系
public class ActivityMain extends MapActivity {

    Button button;
    OnClickListener listener;
    Uri uri = Uri.parse("geo:38.69,118.50");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        setContentView(R.layout.main);
//
//        button = (Button) findViewById(R.id.button);
        listener = new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
            }
        };
        
        setContentView(R.layout.main);
        button = (Button) findViewById(R.id.button);
        
        button.setOnClickListener(listener); // 这个整体的使用情况

    }

    //需要实现这个方法是主要问题
    @Override
    protected boolean isRouteDisplayed() {

        return false;
    }

    // @Override
    // public boolean onCreateOptionsMenu(Menu menu) {
    // // Inflate the menu; this adds items to the action bar if it is present.
    // getMenuInflater().inflate(R.menu.activity_main, menu);
    // return true;
    // }

}

另外,需要对manifest的内容做一定的修改


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myexample.intent0409"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
<!-- 这个权限是需要加入的。。 -->
     <uses-permission android:name="android.permission.INTERNET"/>
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.myexample.intent0409.ActivityMain"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
                
                <!-- 注意添加的以下的语句 -->
            </intent-filter>
            <intent-filter android:priority="0">

                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="geo"/>
                
            </intent-filter>
            
        </activity>
        
        <uses-library android:name="com.google.android.maps"/>
        
        
    </application>
    
   
    
</manifest>


地图的功能还待后续继续实现。。。