2012-09-27 55 views
0

我正嘗試從Android應用程序啓動Google地球6.1,並使用特定的KML文件。以下是我有:用kml文件啓動Google地球

  File file = new File(Environment.getExternalStorageDirectory(), "master.kml"); 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setDataAndType(Uri.fromFile(file), "application/vnd.google-earth.kml+xml"); 
      startActivity(intent); 

我的AndroidManifest.xml是這樣的:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.androidscope" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="15" /> 

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

<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> 

然而,當我跑我得到一個ActivityNotFoundException:

09- 27 14:23:05.290:W/dalvikvm(3525):threadid = 1:線程退出未捕獲的異常(group = 0x400dc760) 09-27 14:23:0 5.290:E/AndroidRuntime(3525):致命例外:主 09-27 14:23:05.290:E/AndroidRuntime(3525):android.content.ActivityNotFoundException:未找到處理Intent的活動{act = android.intent.action .VIEW dat = file:///mnt/sdcard/master.kml typ = application/vnd.google-earth.kml + xml} 09-27 14:23:05.290:E/AndroidRuntime(3525):at android。 app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508) 09-27 14:23:05.290:E/AndroidRuntime(3525):at android.app.Instrumentation.execStartActivity(Instrumentation.java:1382) 09-27 14: 23:05.290:E/AndroidRuntime(3525):at android.app.Activity.startActivityForResult(Activity.java:3095) 09-27 14:23:05.290:E/AndroidRuntime(3525):at android.app.Activity。 startActivity(Activity.java:3201) 09-27 14:23:05.290:E/AndroidRuntime(3525):at com.example .androidscope.MainActivity $ 1.onClick(MainActivity.java:85) 09-27 14:23:05.290:E/AndroidRuntime(3525):at android.view.View.performClick(View.java:3122) 09-27 14:23:05.290:E/AndroidRuntime(3525):在android.view.View $ PerformClick.run(View.java:11942) 09-27 14:23:05.290:E/AndroidRuntime(3525):在android。 os.Handler.handleCallback(Handler.java:587) 09-27 14:23:05.290:E/AndroidRuntime(3525):at android.os.Handler.dispatchMessage(Handler.java:92) 09-27 14: 23:05.290:E/AndroidRuntime(3525):在android.os.Looper.loop(Looper.java:132) 09-27 14:23:05.290:E/AndroidRuntime(3525):at android.app.ActivityThread。 main(ActivityThread.java:4028) 09-27 14:23:05.290:E/AndroidRuntime(3525):at java.lang.reflect.Method.invokeNative(Native Method) 09-27 14:23:05.290:E/AndroidRuntime(3525):在java.lang.reflect.Method.invoke(Method.java:491) 09-27 14:23:05.290:E/AndroidRuntime(3525) :at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:844) 09-27 14:23:05.290:E/AndroidRuntime(3525):at com.android.internal.os.ZygoteInit。主(ZygoteInit.java:602) 09-27 14:23:05.290:E/AndroidRuntime(3525):在dalvik.system.NativeStart.main(本機方法)

我發現,如果我加:

intent.setClassName("com.google.earth", "com.google.earth.EarthActivity"); 

然後谷歌地球加載但沒有KML信息。有沒有人有任何想法?

回答

0

Uri earthURI = Uri.fromFile(kmlFile);

意圖earthIntent = new Intent(android.content.Intent.ACTION_VIEW,earthURI);

startActivity(earthIntent);

0

意圖earthIntent = new Intent(android.content.Intent。ACTION_VIEW,earthURI);

這似乎在Android上5

做工精細有一個Android 6級權限的變化,打破這個意圖是什麼?

相關問題