2011-04-13 89 views
0

嘿,我有一個問題,需要一些幫助與kml文件的路徑。 我想獲取路徑,以便我可以使用intent來打開kml文件。它工作 當我從網上獲得kml,但不是當我把它作爲一個資源。使用android資源路徑獲取kml文件?

感謝

package test1.test; 

import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 
import com.google.android.maps.MapView.LayoutParams; 


public class test11 extends MapActivity { 


     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 



      Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
      Uri.parse("geo:0,0?q=android.resource://test1.test/"+R.raw.skikart)); 
      startActivity(intent); 
     } 

     @Override 
     protected boolean isRouteDisplayed() { 
      // TODO Auto-generated method stub 
      return false; 
     } 
    } 

回答

0

使用下面的代碼ü可以從kmal文件

URLConnection c = mUrl.openConnection(); 
      c.setConnectTimeout(CONNECTION_TIMEOUT); 
      c.setReadTimeout(CONNECTION_TIMEOUT); 
      Log.i("URL===", ""+mUrl); 
      // write connection to file 
      InputStream is = c.getInputStream(); 

      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
      DocumentBuilder db = dbf.newDocumentBuilder(); 
      Document doc = db.parse(is); 
      doc.getDocumentElement().normalize(); 

      Log.i(TAG,"Root Element: "+doc.getDocumentElement().getNodeName()); 
+0

我不能得到的信息,你可以看到什麼毛病從代碼的信息?謝謝 – user705992 2011-04-13 15:20:10

+0

url = new URL(「android.resource://test1.test/skikart」); URLConnection c = url.openConnection(); int CONNECTION_TIMEOUT = 30; c.setConnectTimeout(CONNECTION_TIMEOUT); c.setReadTimeout(CONNECTION_TIMEOUT); Log.i(「URL ===」,「」+ url); InputStream is = c.getInputStream(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(is); doc.getDocumentElement()。normalize(); (TAG,「Root Element:」+ doc.getDocumentElement()。getNodeName()); – user705992 2011-04-13 15:24:41