Click here to Skip to main content
15,888,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to build an app that Syncs with apps from Dropbox Sync API. I have carefully implemented the steps for configuring the Dropbox SYNC API. But i still cannot make the code to function.

package ************;

import java.io.IOException; import java.util.List;

import android.accounts.Account;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.widget.TextView;
import android.os.Handler.Callback;
import com.dropbox.sync.android.DbxAccountManager;
import com.dropbox.sync.android.DbxException;
import com.dropbox.sync.android.DbxFile;
import com.dropbox.sync.android.DbxFileSystem;
import com.dropbox.sync.android.DbxFileInfo;

import com.dropbox.sync.android.DbxPath;

public class LogInActivity extends ActionBarActivity {

private static final String appKey = ""; private static final String appSecret = ""; private static final int REQUEST_LINK_TO_DBX = 0; private Button mLinkButton;

private TextView txtviewres;



private DbxAccountManager mDbxAcctMgr;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in);
mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(),appKey,appSecret);
txtviewres = (TextView) findViewById(R.id.textView5);

mLinkButton = (Button) findViewById(R.id.button1);
mLinkButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{

onClickLinkToDropbox();

}
});
}

@Override
protected void onResume() {
super.onResume();
if (mDbxAcctMgr.hasLinkedAccount()) {
tesfunk();

} else {
txtviewres.setText("Link to Dropbox failed or was cancelled.");
}
}

private void onClickLinkToDropbox() {
mDbxAcctMgr.startLink((Activity)this, REQUEST_LINK_TO_DBX);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LINK_TO_DBX) {
if (resultCode == Activity.RESULT_OK) {
tesfunk();
} else {
txtviewres.setText("Link to Dropbox failed or was cancelled.");
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
private void tesfunk(){ try {

DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());


DbxFile testFile = dbxFs.create(new DbxPath("hello.txt"));
try {
testFile.writeString("Hello Dropbox!");
} finally {
testFile.close();
}



}
catch(IOException e)
{

}
}

@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_log_in, 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);
}
}
Posted
Comments
Richard MacCutchan 22-Jan-15 3:24am    
1. Please format your code correctly (put <pre> tags around it).
2. Explain what the problem is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900