private void publishResults( String a, int p1, int p2, int id, long total, long done, boolean b, boolean move) { if (hash.get(id)) { mBuilder.setProgress(100, p1, false); mBuilder.setOngoing(true); int title = R.string.copying; if (move) title = R.string.moving; mBuilder.setContentTitle(utils.getString(c, title)); mBuilder.setContentText( new File(a).getName() + " " + utils.readableFileSize(done) + "/" + utils.readableFileSize(total)); int id1 = Integer.parseInt("456" + id); mNotifyManager.notify(id1, mBuilder.build()); if (p1 == 100 || total == 0) { mBuilder.setContentTitle("Copy completed"); if (move) mBuilder.setContentTitle("Move Completed"); mBuilder.setContentText(""); mBuilder.setProgress(0, 0, false); mBuilder.setOngoing(false); mBuilder.setAutoCancel(true); mNotifyManager.notify(id1, mBuilder.build()); publishCompletedResult(id, id1); } DataPackage intent = new DataPackage(); intent.setName(a); intent.setTotal(total); intent.setDone(done); intent.setId(id); intent.setP1(p1); intent.setP2(p2); intent.setMove(move); intent.setCompleted(b); hash1.put(id, intent); if (progressListener != null) { progressListener.onUpdate(intent); if (b) progressListener.refresh(); } } else publishCompletedResult(id, Integer.parseInt("456" + id)); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Bundle b = new Bundle(); ArrayList<String> files = intent.getStringArrayListExtra("FILE_PATHS"); String FILE2 = intent.getStringExtra("COPY_DIRECTORY"); mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); b.putInt("id", startId); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.putExtra("openprocesses", true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); mBuilder = new NotificationCompat.Builder(c); mBuilder.setContentIntent(pendingIntent); mBuilder .setContentTitle(getResources().getString(R.string.copying)) .setSmallIcon(R.drawable.ic_content_copy_white_36dp); if (foreground) { startForeground(Integer.parseInt("456" + startId), mBuilder.build()); foreground = false; } b.putBoolean("move", intent.getBooleanExtra("move", false)); b.putString("FILE2", FILE2); b.putStringArrayList("files", files); hash.put(startId, true); DataPackage intent1 = new DataPackage(); intent1.setName(files.get(0)); intent1.setTotal(0); intent1.setDone(0); intent1.setId(startId); intent1.setP1(0); intent1.setP2(0); intent1.setMove(intent.getBooleanExtra("move", false)); intent1.setCompleted(false); hash1.put(startId, intent1); new Doback().execute(b); // If we get killed, after returning from here, restart return START_STICKY; }