1

if I have tile in .png.tile. Is it possible to include it with .apk. my purpose is after I download app from market, when I open the app it should show every tile and every zoom level of at lease 1 country (maybe not big one). PS. I use OSM. PS.2 sorry for my english grammar.

EDIT: one country maybe too large. maybe just one province or one state and some of zoom level.

EDIT2:This is the function i used and what can i do about inputstream thank you very much.

    AssetManager assetManager = getAssets();

    try {
        files = assetManager.list("Map");
    } catch (IOException e) {
        Log.e("tag", e.getMessage());
    }
    try {
        firstField = (EditText) findViewById(R.id.firstId);
        firstField.setText(Integer.toString(files.length)
                + " file. File name is " + files[0]);

    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        inputStream = assetManager.open("Map/mapnik.zip");
        // String s = null;
        // s = readTextFile(inputStream);
        // secondField = (EditText) findViewById(R.id.secondId);
        // secondField.setText(s);
    } catch (IOException e) {
        Toast.makeText(this, "Error" + e.toString(), Toast.LENGTH_SHORT)
                .show();
    }
majorl3oat
  • 4,327
  • 1
  • 18
  • 21

1 Answers1

1

Yes, you can include it by placing it in the assets folder. See http://developer.android.com/reference/android/content/res/AssetManager.html for accessing assets.

mah
  • 39,056
  • 9
  • 76
  • 93
  • thank you for fast reply. All i have to do is use assetManager to pack tile map in and when I open app in onCreate I have to read getAsset() and write to sdcard again? did i understand right? – majorl3oat Mar 06 '12 at 02:39
  • almost. you don't use the asset manager to get the asset in your apk, you simply place the file in your assets folder before you build the apk; it will automatically be packed in by the build process. also, you don't necessarily need to copy the asset out to your sdcard to use it, you may be able to use it directly in place; it can be opened to an InputStream. – mah Mar 06 '12 at 11:25
  • Sorry, I was offline couple days. I completely understand your comment now. But If i have a Mapnik.zip file and this file is need to be unzip in the /sdcard/osmdroid can I get this zip file from assets and unzip this file into directory i mention before? I google about this and found only read txt file by inputStream. thank you very much. – majorl3oat Mar 09 '12 at 01:20
  • What you're asking is possible but not necessary -- in fact, wasteful even. Instead of placing the zip in your assets and copying / unzipping it out, unzip it and leave the unzipped contents in your assets. Remember, your APK is zipped up so these files are compressed, but Android gives you the InputStream so you can access them as if they are regular files. If there's some reason you _must_ have them on the sdcard, you can use the InputStream to read the contents of the file and write it to where you need it. – mah Mar 09 '12 at 02:11
  • thanks you very much. but the inputstream can write file from asset to sdcard if yes, can you explain how to do that please. I'll update question of function i use but it use only file.list and i don't even know how to make inputstream write it. – majorl3oat Mar 09 '12 at 02:21
  • InputStreams don't write, you read from them. You'll need to write code to also create an OutputStream, and to send data from one stream to the other. – mah Mar 09 '12 at 11:38
  • Thanks a lot now it work properly. by the way I just misunderstanding about zip file. actually that zip is no need to extract just copy it from asset to the sdcard and the osm work fine. buts thanks a lot for helping me about this. I'll kept this as android know-how. Thanks – majorl3oat Mar 13 '12 at 01:24