机器人 - 如何打开Android的KML文件 [英] android - how to open kml file in android
问题描述
我保存在我的sdcard.I希望通过谷歌地图在我的应用程序中打开KML文件,所以我用下面的code,但我得到错误说机器人IllegalStateException异常无法执行的方法活动
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"
我不想要绘制地图,一切都只是我想打开它已经存储在SD卡我的KML文件并显示它。
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.
当我谷歌,我得到了很多相关的基础上,借鉴DATAS地图项目,这个我不想。
When i google it i got lot of items related to drawing map based on the datas,this i dont want.
我的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);
}
我的Android清单文件
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>
我的logcat的错误:
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)
我是新来android.Please帮助me..Your帮助是很大的AP preciated。
I am new to android.Please help me..Your help is greatly appreciated.
推荐答案
检查AndroidManifest.xml文件相关的权限,并确保您试图打开(10.kml)文件路径。除了这一切都在你的code罚款。
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.
这篇关于机器人 - 如何打开Android的KML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!