apkã«1MB以ä¸ã®ãã¼ã¿ãã¼ã¹ãã¡ã¤ã«ãå«ãã
かなぶんã®è¾æ¸DBã®ããã«ãã¢ããªã«åæå¤ã¨ãã¦DBãå«ãããå ´åãassetså ã«ä¿åãã¦ãããååèµ·åæã«databasesã«ã³ãã¼ãããã¨ããæ¹æ³ãããã¾ãã
åºæ¬çãªããæ¹ã¯こちらのサイトã§ç´¹ä»ããã¦ããéããªã®ã§ããããã®æ¹æ³ã¯å°ãããã¡ã¤ã«ãªãåé¡ãªãã®ã§ããã1MB以ä¸ã®ãã¡ã¤ã«ã ã¨AssetManagerã§Exceptionãçºçãã¦ãã¾ãã¾ãã
Androidã®AssetManagerã®å é¨ã§ã¯ UNCOMPRESS_DATA_MAX ã¨ããå¤ãå®ç¾©ããã¦ãã¦ãæ©ç¨®ä¾åã«ã¯ãªãã¨æãã¾ãããç¾ç¶åºåã£ã¦ãã端æ«ã§ã¯1024*1024 = 1MBã«è¨å®ããã¦ãã¾ãã
1MB以ä¸ã®DBãæ±ãããã«ã¯
- ãã¡ã¤ã«ãåå²ãã
- ãã¡ã¤ã«ãå§ç¸®ãã
ã®æ¹æ³ãããã¾ãã
æ¹æ³1.ãã¡ã¤ã«ãåå²ãã
æ大1MBã§ãã¡ã¤ã«ããåå²ããååèµ·åæã«åå²ããããã¡ã¤ã«ãçµåããdatabasesã«ä¿åãã¾ãã
åå²ã¯çµåã¨éã®å¦çãæ¸ãããå°ç¨ãã¼ã«ã使ããLinuxãªã
split -b 1m
ã§ã§ãã¾ãã
Androidå´ã§ã¯ååèµ·åæã«ä¸è¨ã®ããã«çµåãä¿åããã¾ãã
public void extractZipFiles(String dest, String zipName) { try { AssetManager assetManager = context.getAssets(); InputStream inputStream = assetManager.open(zipName, AssetManager.ACCESS_STREAMING); ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { String entryName = zipEntry.getName(); int n; FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(dest + "/" + entryName); byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; while ((n = zipInputStream.read(buf, 0, DEFAULT_BUFFER_SIZE)) > -1) { fileOutputStream.write(buf, 0, n); } fileOutputStream.close(); zipInputStream.closeEntry(); zipEntry = zipInputStream.getNextEntry(); } zipInputStream.close(); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }
æ¹æ³2.ãã¡ã¤ã«ãå§ç¸®ãã
DBãzipã§å§ç¸®ãã¦ãããååèµ·åæã«zipã解åããdatabaseså
ã«å
容ãä¿åãã¾ãã
ãããããã¨ã§ãUNCOMPRESS_DATA_MAX ã®å¶éãåããã«èªã¿è¾¼ããã¨ãã§ãã¾ãã
ãã ããDBãã¡ã¤ã«ãåå²ã«ãã¦ãå§ç¸®ã«ãã¦ããapkã¯zipã§å§ç¸®ãããã®ã§apkèªä½ã®ãµã¤ãºæ¸å°ã«ã¯ã¤ãªããã¾ããã
zipã®å§ç¸®ã¯æ§ã ãªãã¼ã«ãåºåã£ã¦ããã®ã§ããã®ã©ããã使ãã°ããã§ãããã解åã®ã¹ããããã¯ä»¥ä¸ã®éãã§ãã
public void extractZipFiles(String dest, String zipName) { try { AssetManager assetManager = context.getAssets(); InputStream inputStream = assetManager.open(zipName, AssetManager.ACCESS_STREAMING); ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { String entryName = zipEntry.getName(); int n; FileOutputStream fileOutputStream; fileOutputStream = new FileOutputStream(dest + "/" + entryName); byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; while ((n = zipInputStream.read(buf, 0, DEFAULT_BUFFER_SIZE)) > -1) { fileOutputStream.write(buf, 0, n); } fileOutputStream.close(); zipInputStream.closeEntry(); zipEntry = zipInputStream.getNextEntry(); } zipInputStream.close(); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }
databases以ä¸ã«ã³ãã¼ãããã¨ã¯é常ã®DBã¨åæ§ã«ä½¿ãã¾ãã
ãã¡ã¤ã«ãµã¤ãºãå°ããã§ãã§ã°ããã«è¶ãããã¨ã¯ãªãã§ããã1MBãã大ãããªã£ã¦ãã¾ãå ´åã®åèã«ã©ããã