X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/164417ec61f1b96823e57a518b79caa611aa0f53..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 a5ee28f8..323faf46 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/src/eu/alefzero/owncloud/files/services/FileDownloader.java @@ -35,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"; @@ -43,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; @@ -85,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); @@ -124,12 +127,16 @@ 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 file = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + mFilePath); try { + file.getParentFile().mkdirs(); file.createNewFile(); } catch (IOException e) { e.printStackTrace(); @@ -137,7 +144,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis 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( @@ -151,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); }