2012-02-16 7 views
1

には外部のjarを使用しており、通常のクラスに加えてhtmlファイルがあります。私の最後のAPKのルートディレクトリを意味APK内のファイルを読み取る

この

  • assests
  • 解像度
  • のAndroidManifest.xml
  • classes.dex
  • resources.arsc
  • helloworld.htmlようになります

私のアプリケーションから最後のファイルにアクセスするには "helloworld.html"?

+2

を見つけることができますが、あなたは資産内のHTMLファイルを保存し、「getAssets(呼び出すことができます) "? – goodm

答えて

1

Androidパッケージ階層は、Javaアプリケーションパッケージと似ていません。 このようなファイルにはアクセスできません。

あなたのアプリケーションではhelloworld.htmlファイルを使用する必要があります。

だから

getAssets()を使用してファイルを取得/assetディレクトリにし、あなたのアクティビティコードでこのファイルを置きます。 jarファイルの代わりにライブラリプロジェクトをしていないのはなぜfile:///android_asset/helloworld.html

+0

これは私が望むものではありません。私は開発者に瓶を与えています。私はそれらに瓶を使用してもらいたいと言いません - "さらに、このhtmlファイルを資産ディレクトリに入れてください" – Omer

+0

私の答えはあなたの質問に関連しています.. "私のアプリケーションから最後のファイル "helloworld.html"へのアクセス? " – user370305

+0

申し訳ありませんが、わかりませんでした。 htmlファイルはassetsディレクトリにありません – Omer

0

ものようなファイルにアクセスしますか?あなたはあなたのファイルで「assets/SecureManifest.xmlを」文字列を置換する必要が

0

helloworld.html

public static InputStream getInputStreamFromApkResource(String apkFilePath, String apkResPath) throws IOException { 
    JarFile jarFile = new JarFile(apkFilePath); 
    JarEntry jarEntry = jarFile.getJarEntry(apkResPath); 
    return jarFile.getInputStream(jarEntry); 
} 

// Example usage reading the file "SecureManifest.xml" under "assets" folder: 
File sdcard = Environment.getExternalStorageDirectory(); 
File apkFile = new File(sdcard, "file.apk"); 
if (apkFile.exists()) { 
    try { 
     InputStream is =getInputStreamFromApkResource(apkFile.toString(), "assets/SecureManifest.xml"); 
     BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
     String str; 
     while ((str = br.readLine()) != null) { 
      Log.d("***", str); 
     } 

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

githubのの要旨はhere

関連する問題