Get kml-file using android resource path?
Hey, i have a problem, need some help with the path for the kml-file. I want to get the path so i can use intent to open the kml-file. It works when i get the the kml from the web, but not when i got it as a resource.
Thanks
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;
}
}
use the below code u can get the information from the kmal file
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());
精彩评论