PDA

View Full Version : پیدا کردن مسیر پوشه assets



Ebrahimkh
جمعه 26 تیر 1394, 15:39 عصر
سلام دوستان

من تو برنامم یه فایل رو از نت دانلود می کنم می خوام تو پوشه assets برنامم ذخیره بشه اما نمیدونم چجوری باید این مسیر رو بدست بیارم
با کد زیر تست کردم جواب نداد




Environment.getExternalStorageDirectory().getAbsol utePath()+"/Android/data/"+PACKAGE_NAME+"/databases/";

Ebrahimkh
جمعه 26 تیر 1394, 17:55 عصر
دوستان راهی سراغ ندارید ؟؟!!؟؟

Ebrahimkh
شنبه 27 تیر 1394, 07:27 صبح
up---------------

hosseinaryai
شنبه 27 تیر 1394, 07:49 صبح
من معمولن با متد زیر اول هر چی توی assets دارمو میریزم توی گوشی طرف ، بعد ازشون استفاده می کنم ، ببین به کارت میاد :


public static void copyAssets(Context cot,String mypath) {
AssetManager assetManager = cot.getAssets();
String[] files = null;

try {
files = assetManager.list("");
} catch (IOException e) { }

for(String filename : files) {
InputStream in = null;
OutputStream out = null;

try {
in = assetManager.open(filename);
out = new FileOutputStream(mypath + filename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(Exception e) { }
}
}
public static void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}

Ebrahimkh
یک شنبه 28 تیر 1394, 08:40 صبح
سلام حسین جان
بابت سورس منون
------------------------------

من می خوام یه فایل رو از نت دانلود کنم و کپیش کنم تو پوشه assets برنامه حالا نمیدونم مسیر assets برنامم رو چجوری بدست بیارم

peymanf11
یک شنبه 28 تیر 1394, 08:50 صبح
سلم دوست عزیز


private void copyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.e("tag", "Failed to get asset file list.", e);
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(filename);
File outFile = new File(getExternalFilesDir(null), filename);
out = new FileOutputStream(outFile);
copyFile(in, out);
} catch(IOException e) {
Log.e("tag", "Failed to copy asset file: " + filename, e);
}
finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// NOOP
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
// NOOP
}
}
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}




منبع (http://thedevelopersinfo.com/2009/11/17/using-assets-in-android/)

#root#
یک شنبه 28 تیر 1394, 08:51 صبح
من می خوام یه فایل رو از نت دانلود کنم و کپیش کنم تو پوشه assets برنامه حالا نمیدونم مسیر assets برنامم رو چجوری بدست بیارم

داخل assets یا هیج جایی دیگه از فایل apk نمیتونید تغییری ایجاد کنید. همون مسیر پیشفرض دیتابیس مناسب هست.