رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

پست های پیشنهاد شده

با سلام.

من می خواستم تعدادی فایل مورد نیاز برای برنامه ام را دانلود کنم.اما در حالت عادی که دانلود انجام می شود.بعضی از مواقع دانلود متوقف می شود.به همین خاطر به فکر استفاده از سرویس افتادم که در آن عملیات دانلود را  startForeground  انجام دهم.اما نمی دانم پروگرس دانلود را باید چگونه برای قرار دادن در نوتیفیکیشن بار ایجاد کرد.لطفا راهنمایی کنید.

لینک ارسال
به اشتراک گذاری در سایت های دیگر

سلام آقای سرسیفی ممنون می شم اگه زودتر جوا بدین چون هزینه کرده ام و سرور تهیه کردم اما الان به مشکل برخوردم. اینم کد.

public class DownloadService extends Service {   public static String    name;      NotificationManager     notificationManager;   int                     lenghtOfFile;   int                     total                    = 0;   @Override   public void onCreate() {       super.onCreate();       Log.d("Testing", "Service got created");       Toast.makeText(this, "ServiceClass.onCreate()", Toast.LENGTH_LONG).show();   }   @Override   public void onDestroy() {       super.onDestroy();   }   @Override   public void onStart(final Intent intent, int startId) {       super.onStart(intent, startId);       Toast.makeText(this, "ServiceClass.onStart()", Toast.LENGTH_LONG).show();       Log.d("Testing", "Service got started");       final NotificationManager notificationManager = (NotificationManager)               getSystemService(NOTIFICATION_SERVICE);       final Notification notification = new Notification(R.drawable.ic_launcher, getText(R.string.app_name),               System.currentTimeMillis());       Intent notificationIntent = new Intent(this, DownloadService.class);       PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);       notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;       notification.contentView = new RemoteViews(getApplicationContext().getPackageName(),               R.layout.dv);       notification.contentIntent = pendingIntent;       notification.contentView.setImageViewResource(R.id.imageView1, R.drawable.ic_launcher);       notification.contentView.setTextViewText(R.id.textView1, "simulation in progress");       notification.contentView.setProgressBar(R.id.progressBar, 100, 0, false);       startForeground(1234, notification);       new Thread(new Runnable() {           @Override           public void run() {               try {                   int count;                   URL url = new URL("http://www.novineedeh.ir/tanz26.mp4");                   URLConnection conexion = url.openConnection();                   conexion.connect();                   lenghtOfFile = conexion.getContentLength();                   InputStream input = new BufferedInputStream(url.openStream(), 8192);                   File k = new File("sdcard/Sad/", "t.mp4");                   OutputStream output = new FileOutputStream(k);                   byte data[] = new byte[lenghtOfFile];                   total = 0;                   while ((count = input.read(data)) != -1) {                       total += count;                       output.write(data, 0, count);                       notification.contentView.setProgressBar(R.id.progressBar, lenghtOfFile, total, false);                       notificationManager.notify(1234, notification);                   }                   Log.d("ANDRO_ASYNC", "end download ");                   output.flush();                   output.close();                   input.close();                   stopService(intent);               }               catch (MalformedURLException e) {                   e.printStackTrace();                   stopService(intent);               }               catch (IOException e) {                   e.printStackTrace();                   stopService(intent);               }           }       }).start();   }   @Override   public IBinder onBind(Intent arg0) {       return null;   }}

وقتی که برنامه رو اجرا می کنم.بعد از اینکه مقداری از دانلود میگذره اسلایدینگ دراور(نوار نوتیفیکیشن) بالای صفحه از کار می افته.فکر کنم به خاطر اینکه آپدیت پروگرس بار درون حلقه وایل هست و هرچه فکر کردم چیزی به ذهنم نرسید.در ضمن چگونه درصد دانلود را زیر پروگرسبار نمایش دهم؟. مدیران خواهشا کمک کنید.

لینک ارسال
به اشتراک گذاری در سایت های دیگر

مشکلم حل شد.فقط یک سوال.حتما موقع دانلود یه برنامه از بازار یا گوگل پلی یا اینترنت دیدید که یک علامت دانلود متحرک(انیمیشن)ظاهر میشه.اونو چه جوری باید به برنامه اضافه کنم.

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...