X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/24a1111aa117f9d825646c23909e39a0d12f43b8..3ce234e6c7858443738b71bd74dba4f754ce13a1:/src/eu/alefzero/owncloud/files/services/FileDownloader.java diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java index 087b103e..323faf46 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/src/eu/alefzero/owncloud/files/services/FileDownloader.java @@ -1,6 +1,7 @@ package eu.alefzero.owncloud.files.services; import java.io.File; +import java.io.IOException; import android.accounts.Account; import android.accounts.AccountManager; @@ -34,6 +35,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; public static final String EXTRA_FILE_PATH = "FILE_PATH"; + public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH"; public static final String EXTRA_FILE_SIZE = "FILE_SIZE"; private static final String TAG = "FileDownloader"; @@ -42,6 +44,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis private ServiceHandler mServiceHandler; private Account mAccount; private String mFilePath; + private String mRemotePath; private int mLastPercent; private long mTotalDownloadSize; private long mCurrentDownlodSize; @@ -84,6 +87,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT); mFilePath = intent.getStringExtra(EXTRA_FILE_PATH); + mRemotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; mServiceHandler.sendMessage(msg); @@ -123,17 +127,24 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis mNotification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.progressbar_layout); mNotification.contentView.setProgressBar(R.id.status_progress, 100, 0, mTotalDownloadSize == -1); mNotification.contentView.setImageViewResource(R.id.status_icon, R.drawable.icon); + // dvelasco ; contentIntent MUST be assigned to avoid app crashes in versions previous to Android 4.x ; + // BUT an empty Intent is not a very elegant solution; something smart should happen when a user 'clicks' on a download in the notification bar + mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT); mNotificationMngr.notify(1, mNotification); File sdCard = Environment.getExternalStorageDirectory(); - File dir = new File(sdCard.getAbsolutePath() + "/owncloud"); - dir.mkdirs(); - File file = new File(dir, mFilePath.replace('/', '.')); + File file = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + mFilePath); + try { + file.getParentFile().mkdirs(); + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString()); Log.e(TAG, mFilePath+""); - if (wdc.downloadFile(mFilePath, file)) { + if (wdc.downloadFile(mRemotePath, file)) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath()); getContentResolver().update( @@ -147,6 +158,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } mNotificationMngr.cancel(1); Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE); + end.putExtra(EXTRA_FILE_PATH, file.getAbsolutePath()); sendBroadcast(end); }