0
چگونگی گرفتن فایل موزیک در وب سرور برنامه اندروید و درگاه پرداخت
سلام دوستان
- آموزش چگونگی گرفتن فایل موزیک از وب سرور برای برنامه اندروید را می خواستم.
- آموزش پرداخت درون برنامه ای از طریق زرین پال یا پارس پی
ممنون
1 پاسخ
1
سلام به شما دوست عزیز
برای دانلود فایل از سرور از کد زیر استفاده کنید
private class DownloadFile extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... url) {
int count;
try {
URL url = new URL("url of your .mp3 file");
URLConnection conexion = url.openConnection();
conexion.connect();
// this will be useful so that you can show a tipical 0-100% progress bar
int lenghtOfFile = conexion.getContentLength();
// downlod the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/somewhere/nameofthefile.mp3");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
publishProgress((int)(total*100/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;
}
همچنین باید مجوز های زیر را نیز داشته باشید
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission>