4

アプリケーションがデバイス上にあるときに、アプリケーションで使用する必要があるファイルがいくつかあります。現在、これらのファイルをコピーし、コンピュータを手動で使用してデバイスに直接貼り付けることによってのみ、これを行うことができます。

したがって、これらのファイルをapkにパックまたはコピーしてデバイスにインストールする方法はありますか?プログラムはそれらを貼り付けて、デバイス内のフォルダーを自動的に指定します

パックしたいファイルは、Sphinx 音声認識のモデルです

感謝。

4

1 に答える 1

4

ファイルをプロジェクトの /assets ディレクトリに配置すると、ファイルが apk に直接ビルドされ、ファイルにアクセスしてコピーするか、実行時にオブジェクトのgetAssets()メソッドを使用して必要なものにアクセスできます。Context

InputStream input = context.getAssets().open("your_file_name");
String outPath = "/some/path/your_file_name";
OutputStream output = new FileOutputStream(outPath);

// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
    output.write(buffer, 0, length);
}

// Close the streams
output.flush();
output.close();
input.close();
于 2012-03-24T03:49:44.033 に答える