Sending file to dropbox from android - android

i am doing work on drop box through android, i need create a folder and send a file(Eg: .txt file) to that folder from SD card of the mobile.. I can successfully create folders using the following statement
Entry entry = api.createFolder("dropbox", "test_folder");
how can i send file from SD card to dropbox folder, i have searched in https://www.dropbox.com/developers/docs
but i didnt find the right solution yet, please give me the solution to send file to folder in dropbox.
Please help me, thanks in advance....

Perhaps you would like to use the Android-Api and have a look at
public int putFile(String root, String dbPath, File localFile)
and
public File getFile(String root, String dbPath, File localFile, String etag)
I think it's usage is straight-forward.

Related

How to get asset file path in Xamarin?

I have data.xlsx file in Assets folder and need to get its path to apply some library.
Found several solutions here but neither works for me. For example -
File Not Found Exception In Xamarin program
I tried to use file:///android_asset/data.xlsx but here is no file too.
I checked the path with: System.IO.File.Exists(filePath);
So how to get path to this file? Maybe I have to place it in different folder?
Update: possibly I can solve it this way: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
But I can't find where to place it.
Update: this question is about Java and this is unclear how to use this solution in Xamarin.Android: How to get the android Path string to a file on Assets folder?
Looks like the file isn't included in the APK. Ensure that the Build Action of the file in the Asset-folder is set to AndroidAsset.
in general using Xamarin.android , you can use this code :
private string _fileName {get;set;}
public string FileFullPath
{
get
{
return Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures),_fileName);
}
}
Hope it helps.. :)
Looks like it's impossible.
Closest solution is to write file to Cache.

Problems reading file from ddms in android?

The file i want to open is located in the file:
/data/data/MY_PACKAGE/files/samplefile.txt
I have pulled the file from ddms and the desired content is in it
I just want to get the text file in order to parse it..
I tried the following:
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File xmlFile = new File(sdcard,"samplefile.txt");
but no joy...
Thanks in advance!!
Use getFilesDir(), not Environment.getExternalStorageDirectory(), to get at the root of internal storage, where your file resides.
In order to open a file stored within your applications private directory you must use openFileInput(String fileName). This will return a FileInputStream that you can then work with.

File not found issue in Android

I need to access myfile.txt file using FileReader in Android , please suggest me where to add the text file in Eclipse. I tried it adding it in Resource and Asset but I am getting File not found issue.
FileReader fr = new FileReader("myfile.txt");
Even
File ff = new File("myfile.txt");
File Supports only the below listed parameters
FileReader Supports only the below listed parameters
Note: I want solution for this issue , only with FileReader or File
The directory would be /res/raw/ this is where you put all your extra resources.
you can refer to it using getResources().openRawResource(resourceName)
and check here Android how to get access to raw resources that i put in res folder?
EDIT:
how can i edit the text files in assets folder in android
in short
the easiest way would be to copy the file to external directory then do your stuff there
link is here
Android: How to create a directory on the SD Card and copy files from /res/raw to it?
One thing to mention - prior to 2.3 the file size in the assets cannot exceed 1MB.
hope it helps abit
That's how I obtain my file from the SD card, perhaps this can be some use to you.
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File options = new File(getAppDirectory(), "portal.xml");
}
The getAppDirectory method used in the bit of code looks like this :
private String getAppDirectory() {
return new String(Environment.getExternalStorageDirectory().toString()
+ "/foldername/foldername/");
}
After this bit of code I also make sure the file exists and what not before I attempt to read from it.

How to read file that belongs to other app from external storage?

I want to read text file, that was written by other my app. It's saved ad "Android/data/MyPackageName/files/"
I use this code:
File file = new File("//Android//data//MyPackageName//files//", "filename.txt");
FileInputStream is = new FileInputStream(file);
but i get exception "no such file or directory"
I am sure that solution is pretty simple, but i can't find it yet.
Thank you for your help!
I don't think it is right to use the double backslash "//", one is enough. Also, the path should be "/mnt/sdcard/Android/data....". I am not sure the "/mnt/sdcard" is applicable on every device, so my suggestion is to use Environment.getExternalStorageDirectory to get the root dir on sd card.

android: Check the existence of a file in the application

I have few html files in assets folder of my application. My application loads these files depending on the device language. When I check for the existance of the file it say does not exist, but when I load that file using browser.loadUrl(filename), it loads it fine.
Following code will help you to understand my problem:
String filename="file:///android_asset/actualfilemname.html";
File f = new File(filename);
if(!f.exist){
filename = "file:///android_asset/newfile.html";[Everytime it loads this file even though I have actualfilename.html in the folder]
}
browser.loadUrl(filename);
[it loads the newfile.html but not actualfilename.html]
You can't use File for resources. You'll need to use the AssetManager for that.
(In the off-chance that File does handle resources, which I don't think it does, you'll have to convert the path to a URI first, for example using URI.create(). File(String) expects a path, not a URI.)
Is this the exact code you are using? you probably want to be calling f.exists() not filename.exist().
Edit: try working with the AssetManager instead of hard coding your file path. My best guess is that the file path you are using is not exactly how it supposed to be.

Categories

Resources