- \r
- nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);\r
- \r
- Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);\r
- String file_path = intent.getStringExtra(EXTRA_FILE_PATH);\r
- AccountManager am = (AccountManager)getSystemService(ACCOUNT_SERVICE);\r
- Uri oc_url = Uri.parse(am.getUserData(account, AccountAuthenticator.KEY_OC_URL));\r
-\r
- WebdavClient wdc = new WebdavClient(oc_url);\r
- \r
- String username = account.name.split("@")[0];\r
- String password = "";\r
- try {\r
- password = am.blockingGetAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE, true);\r
- } catch (Exception e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- return START_NOT_STICKY;\r
+\r
+ void downloadFile() {\r
+ AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
+ String oc_base_url = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);\r
+ OwnCloudVersion ocv = new OwnCloudVersion(am\r
+ .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION));\r
+ String webdav_path = AccountUtils.getWebdavPath(ocv);\r
+ Uri oc_url = Uri.parse(oc_base_url+webdav_path);\r
+\r
+ WebdavClient wdc = new WebdavClient(Uri.parse(oc_base_url + webdav_path));\r
+\r
+ String username = mAccount.name.split("@")[0];\r
+ String password = "";\r
+ try {\r
+ password = am.blockingGetAuthToken(mAccount,\r
+ AccountAuthenticator.AUTH_TOKEN_TYPE, true);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ return;\r
+ }\r
+\r
+ wdc.setCredentials(username, password);\r
+ wdc.allowUnsignedCertificates();\r
+\r
+ Notification n = new Notification(R.drawable.icon, "Downloading file",\r
+ System.currentTimeMillis());\r
+ PendingIntent pi = PendingIntent.getActivity(this, 1, new Intent(this,\r
+ FileDisplayActivity.class), 0);\r
+ n.setLatestEventInfo(this, "Downloading file", "Downloading file "\r
+ + mFilePath, pi);\r
+ nm.notify(1, n);\r
+\r
+ File sdCard = Environment.getExternalStorageDirectory();\r
+ File dir = new File(sdCard.getAbsolutePath() + "/owncloud");\r
+ dir.mkdirs();\r
+ File file = new File(dir, mFilePath.replace('/', '.'));\r
+\r
+ Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString());\r
+ Log.e(TAG, mFilePath+"");\r
+ if (wdc.downloadFile(mFilePath, file)) {\r
+ ContentValues cv = new ContentValues();\r
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath());\r
+ getContentResolver().update(\r
+ ProviderTableMeta.CONTENT_URI,\r
+ cv,\r
+ ProviderTableMeta.FILE_NAME + "=? AND "\r
+ + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",\r
+ new String[] {\r
+ mFilePath.substring(mFilePath.lastIndexOf('/') + 1),\r
+ mAccount.name }); \r
+ }\r
+ nm.cancel(1);\r
+ Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);\r
+ sendBroadcast(end);\r