简体   繁体   中英

android - how to open kml file in android

I got a kml file stored in my sdcard.I want to open it through the google map in my app, so i used the below code but i am getting error saying "android illegalstateexception could not execute method of the activity"

I dont want to draw map and all just i want to open a kml file which is already stored in my sdcard and show it.

When i google it i got lot of items related to drawing map based on the datas,this i dont want.

My code :

public void showmap(View v){

    File file = new File(Environment.getExternalStorageDirectory(), "10.kml");
    Intent map_intent = new Intent(Intent.ACTION_VIEW);
    map_intent.setClassName("com.google.earth", "com.google.earth.EarthActivity");
    map_intent.setDataAndType(Uri.fromFile(file), "application/vnd.google-earth.kml+xml");
    startActivity(map_intent);
}

My Android Manifest File

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

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="16" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CAMERA" /> 

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.lyold.LoginActivity"
            android:screenOrientation="landscape"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:screenOrientation="landscape"
            android:name=".Home" />

        <activity android:name="com.google.earth.EarthActivity" android:screenOrientation="landscape"/>




    </application>

</manifest>

My logcat error :

04-04 18:01:05.387: E/AndroidRuntime(5846): FATAL EXCEPTION: main
04-04 18:01:05.387: E/AndroidRuntime(5846): java.lang.IllegalStateException: Could not execute method of the activity
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.view.View$1.onClick(View.java:3044)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.view.View.performClick(View.java:3511)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.view.View$PerformClick.run(View.java:14105)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.os.Handler.handleCallback(Handler.java:605)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.os.Looper.loop(Looper.java:137)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at java.lang.reflect.Method.invokeNative(Native Method)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at java.lang.reflect.Method.invoke(Method.java:511)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at dalvik.system.NativeStart.main(Native Method)
04-04 18:01:05.387: E/AndroidRuntime(5846): Caused by: java.lang.reflect.InvocationTargetException
04-04 18:01:05.387: E/AndroidRuntime(5846):     at java.lang.reflect.Method.invokeNative(Native Method)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at java.lang.reflect.Method.invoke(Method.java:511)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.view.View$1.onClick(View.java:3039)
04-04 18:01:05.387: E/AndroidRuntime(5846): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/10.kml typ=application/vnd.google-earth.kml+xml }
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.app.Activity.startActivityForResult(Activity.java:3190)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at android.app.Activity.startActivity(Activity.java:3297)
04-04 18:01:05.387: E/AndroidRuntime(5846):     at com.example.ashadegreen.Basement.showmap(Basement.java:106)

I am new to android.Please help me..Your help is greatly appreciated.

Check the AndroidManifest.xml FILE related permission and make sure that File Path that you are trying to open (10.kml). Other than this everything is fine in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM