0

I have made an app that works ok, but only for ideal case of downloading .kml to /sdcard/download/.kml.

I would like to make it proper. So the current code is:

public void dwnldKmlKorculaOrlandusa(View v)
{
    Intent dwnldKmlKorculaOrlandusa = new Intent();
    dwnldKmlKorculaOrlandusa.setAction(Intent.ACTION_VIEW);
    dwnldKmlKorculaOrlandusa.setData(Uri.parse("http://www.visitkorcula.eu/downloads/bike-trails/korcula-orlandusa.kml"));
    startActivity(dwnldKmlKorculaOrlandusa);
}

public void openKmlKorculaOrlandusa(View v)
{ 
    Intent openKmlKorculaOrlandusa = new Intent();
    openKmlKorculaOrlandusa.setAction(Intent.ACTION_VIEW);
    File kmlKorculaOrlandusa = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + "download" + File.separator + "korcula-orlandusa.kml"); //"/sdcard/download/korcula-orlandusa.kml"
    openKmlKorculaOrlandusa.setDataAndType(Uri.fromFile(kmlKorculaOrlandusa), "application/vnd.google-earth.kml+xml");
    startActivity(openKmlKorculaOrlandusa);
}

The app downloads *.kml from link (ideally, if it's the older Maps on phone it opens kml in it than) to download folder. On other click it opens it with app that you select (preferably Orux maps).

How to make this proper -> download to specific location and than running it from there?

Or even better, how to provide *.kml's with app and that app then can run kml without need of internet, just calling it from specific location?

Tim
  • 8,932
  • 4
  • 43
  • 64

2 Answers2

0

If you kml is not going to change often you can package it with your apk by putting it in the assets folder of your project.

Then you can copy the kml file to the desired directory. take a look at How to copy files from 'assets' folder to sdcard?

Community
  • 1
  • 1
antonio
  • 18,044
  • 4
  • 45
  • 61
0

You can place any file in your assets folder. You can then get an InputStream of the file like so:

Context.getAssets().open("myKml.kml")
tachyonflux
  • 20,103
  • 7
  • 48
  • 67