Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Demo B.
10 years agoNew member | Level 1
How to access a directory programatically with java android code in dropbox
Not able to provide the correct path to upload a file programatically in dropbox.
putfile() can be used..But the path i am not able to provide . Searching for last 4 hours.Not able to find a soluti...
Demo B.
10 years agoNew member | Level 1
private DropboxAPI<AndroidAuthSession> mDBApi;//global variable
final static private String APP_KEY = "abc";
final static private String APP_SECRET = "xyz";
class forPutFile extends AsyncTask<String,String,Boolean>
{
@Override
protected Boolean doInBackground(String... params)
{
Log.d("mhk","indoInBackground");
File file = new File(Environment.getExternalStorageDirectory()+"/hello.txt");
FileInputStream inputStream = null;
Log.d("mhk","file created..");
try
{
Log.d("mhk","updating inputstream.");
inputStream = new FileInputStream(file);
Log.d("mhk","inputstream is :"+inputStream);
}
catch (FileNotFoundException e)
{
Log.e("mhk", "inputstreamException is : " + e.getMessage());
}
try
{
DropboxAPI.Entry response = new DropboxAPI.Entry();
Log.d("mhk","Uploading file..."+response.root);
response = mDBApi.putFile(response.root+"/hello.txt", inputStream,file.length(), null, null);
Log.d("mhk","File Uploaded..."+response);
}
catch (DropboxException e)
{
Log.e("mhk", "dropboxException is :" + e.getMessage());
}
Log.d("mhk", "The uploaded file's rev is: ");//+ response.rev);
return false; }}
void savingToDropbox(){ try {
try
{
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
mDBApi.getSession().startOAuth2Authentication(MainActivity.this);
new forPutFile().execute("Hii");
}
catch (Exception e1)
{
Log.e("mhk", "DropboxException" + e1.getMessage());
}
}
catch (Exception e)
{
Log.e("mhk", "FileNotFoundException" + e.getMessage());
}
}
protected void onResume()
{
super.onResume();
if (mDBApi.getSession().authenticationSuccessful())
{
try
{
// Required to complete auth, sets the access token on the session
mDBApi.getSession().finishAuthentication();
String accessToken = mDBApi.getSession().getOAuth2AccessToken();
}
catch (IllegalStateException e)
{
Log.e("mhk", "Error authenticating", e);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
savingToDropbox();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
11-13 08:27:49.385 18716-18736/? D/mhk﹕ indoInBackground
11-13 08:27:49.385 18716-18736/? D/mhk﹕ file created..
11-13 08:27:49.385 18716-18736/? D/mhk﹕ updating inputstream.
11-13 08:27:49.505 18716-18736/? D/mhk﹕ inputstream is :java.io.FileInputStream@419d4e98
11-13 08:27:49.555 18716-18736/? D/mhk﹕ Uploading file...null
11-13 08:27:49.555 18716-18736/? E/mhk﹕ dropboxException is :null
11-13 08:27:49.555 18716-18736/? D/mhk﹕ The uploaded file's rev is:
This is the full snippet. But it is giving exception ... Having all those permissions and everything in manifest file.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!