PendingIntent pi = PendingIntent.getActivity(this, 1, new Intent(this, OwnCloudMainScreen.class), 0);
n.setLatestEventInfo(this, "A", "B", pi);
nm.notify(1, n);
-
+
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/owncloud");
dir.mkdirs();
- File file = new File(dir, "filename");
+ File file = new File(dir, file_path.replace('/', '.'));
wdc.downloadFile(file_path, file);
}
getListView().invalidate();
} else {
- try {
Intent i = (Intent) getListAdapter().getItem(position);
if (i.hasExtra("toDownload")) {
- Uri data = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath() + "/owncloud/filename");
- Log.d("DUPA", data.toString());
- File f = new File(data.toString());
- FileInputStream fis = new FileInputStream(f);
- byte buffer[] = new byte[512];
- fis.read(buffer);
- Log.d("DUPA", new String(buffer));
-
Intent intent = new Intent(this, FileDownloader.class);
intent.putExtra(FileDownloader.EXTRA_FILE_PATH, "/"+((TextView)findViewById(R.id.textView1)).getText().toString());
intent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
startActivity(i);
}*/
}
- } catch (ClassCastException e) {} catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+
}
}
package eu.alefzero.owncloud;
+import java.io.File;
+import java.net.FileNameMap;
+import java.net.URI;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Stack;
throw new IllegalArgumentException("Unknown dialog id: " + id);
}
}
-
+
class a implements OnClickListener {
String mPath;
EditText mDirname;
}
for (int i = 0; i < mUploadStreams.size(); ++i) {
- final Cursor c = getContentResolver().query((Uri) mUploadStreams.get(i), null, null, null, null);
- c.moveToFirst();
-
- if (!wdc.putFile(c.getString(c.getColumnIndex(Media.DATA)),
- mUploadPath+"/"+c.getString(c.getColumnIndex(Media.DISPLAY_NAME)),
- c.getString(c.getColumnIndex(Media.MIME_TYPE)))) {
- mHandler.post(new Runnable() {
- public void run() {
- Uploader.this.onUploadComplete(false, "Error while uploading file: " + c.getString(c.getColumnIndex(Media.DISPLAY_NAME)));
- }
- });
+ Uri uri = (Uri) mUploadStreams.get(i);
+ if (uri.getScheme().equals("content")) {
+ final Cursor c = getContentResolver().query((Uri) mUploadStreams.get(i), null, null, null, null);
+ c.moveToFirst();
+
+ if (!wdc.putFile(c.getString(c.getColumnIndex(Media.DATA)),
+ mUploadPath+"/"+c.getString(c.getColumnIndex(Media.DISPLAY_NAME)),
+ c.getString(c.getColumnIndex(Media.MIME_TYPE)))) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ Uploader.this.onUploadComplete(false, "Error while uploading file: " + c.getString(c.getColumnIndex(Media.DISPLAY_NAME)));
+ }
+ });
+ }
+ } else if (uri.getScheme().equals("file")) {
+ final File file = new File(Uri.decode(uri.toString()).replace(uri.getScheme()+"://", ""));
+ FileNameMap fileNameMap = URLConnection.getFileNameMap();
+ String contentType = fileNameMap.getContentTypeFor(uri.toString());
+ if (contentType == null) {
+ contentType = "text/plain";
+ }
+ if (!wdc.putFile(file.getAbsolutePath(), mUploadPath+"/"+file.getName(), contentType)) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ Uploader.this.onUploadComplete(false, "Error while uploading file: " + file.getName());
+ }
+ });
+ }
}
+
}
mHandler.post(new Runnable() {
public void run() {
package eu.alefzero.owncloud;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
return false;
}
- InputStreamReader isr = new InputStreamReader(response.getEntity().getContent());
+ BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent());
FileOutputStream fos = new FileOutputStream(targetPath);
- int oneByte;
- while ((oneByte = isr.read()) != -1) fos.write(oneByte);
+
+ byte[] bytes = new byte[512];
+ int readResult;
+ while ((readResult = bis.read(bytes)) != -1) fos.write(bytes, 0, readResult);
} catch (IOException e) {
e.printStackTrace();
*/
Log.i(TAG, "Uploading, done");
} catch (final Exception e) {
- Log.i(TAG, e.getLocalizedMessage());
+ Log.i(TAG, ""+e.getMessage());
result = false;
}