从Android应用程序将文件上载到Dropbox
我正在尝试将文本文件上载到Dropbox。身份验证工作正常,但当它尝试上载文件时,应用程序崩溃。这是我的密码从Android应用程序将文件上载到Dropbox,android,dropbox-api,Android,Dropbox Api,我正在尝试将文本文件上载到Dropbox。身份验证工作正常,但当它尝试上载文件时,应用程序崩溃。这是我的密码 public class Dropboxupload extends Activity { final static private String APP_KEY = "KEY"; final static private String APP_SECRET = "SECRET"; final static private AccessType ACCESS_TY
public class Dropboxupload extends Activity {
final static private String APP_KEY = "KEY";
final static private String APP_SECRET = "SECRET";
final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;
private DropboxAPI<AndroidAuthSession> mDBApi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
mDBApi.getSession().startAuthentication(Dropboxupload.this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dropboxupload, menu);
return true;
}
/* Called when the application resumes */
@Override
protected void onResume()
{
super.onResume();
if (mDBApi.getSession().authenticationSuccessful()) {
try {
// Required to complete auth, sets the access token on the session
mDBApi.getSession().finishAuthentication();
AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair();
} catch (IllegalStateException e) {
Log.i("DbAuthLog", "Error authenticating", e);
}
String filePath = getApplicationContext().getFilesDir().getPath().toString() + "/magnus-opus.txt";
File file = new File(filePath);
try {
file.createNewFile();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
com.dropbox.client2.DropboxAPI.Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream,
file.length(), null, null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev);
} catch (DropboxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void writeToFile(String data,String filepath, String filename) {
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(openFileOutput(filepath, Context.MODE_PRIVATE));
outputStreamWriter.write(data);
outputStreamWriter.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
}
您正试图在主线程上执行网络操作,这是禁止的,以避免阻塞UI。有关详细信息,请参阅。您正试图在主线程上执行网络操作,这是禁止的,以避免阻塞UI。有关详细信息,请参阅。您正试图在主线程上执行网络操作,这是禁止的,以避免阻塞UI。有关详细信息,请参阅。您正试图在主线程上执行网络操作,这是禁止的,以避免阻塞UI。有关详细信息,请参阅。问题在于线路
final static private String APP_KEY = "KEY";
final static private String APP_SECRET = "SECRET";
您应该填写Dropbox提供的值。问题在于行
final static private String APP_KEY = "KEY";
final static private String APP_SECRET = "SECRET";
您应该填写Dropbox提供的值。问题在于行
final static private String APP_KEY = "KEY";
final static private String APP_SECRET = "SECRET";
您应该填写Dropbox提供的值。问题在于行
final static private String APP_KEY = "KEY";
final static private String APP_SECRET = "SECRET";
您应该填写Dropbox提供的值。什么是“不工作”?请在问题中添加新的错误。我已经添加了新的日志,没有出现错误,但是有一些警告导致它停止上传过程“不工作”是什么意思?请在问题中添加新的错误。我已经添加了新的日志,没有出现错误,但是有一些警告导致它停止上传过程“不工作”是什么意思?请在问题中添加新的错误。我已经添加了新的日志,没有出现错误,但是有一些警告导致它停止上传过程“不工作”是什么意思?请将新错误添加到问题中。我已添加了新日志,没有出现错误,但出现了一些警告,导致其停止上载进程Dropbox拒绝您访问,但您的代码看起来正常。你是否正确地遵循了他们的设置程序?是的,一切正常。不幸的是,Dropbox不起作用,拒绝您访问,但您的代码看起来正常。你是否正确地遵循了他们的设置程序?是的,一切正常。不幸的是,Dropbox不起作用,拒绝您访问,但您的代码看起来正常。你是否正确地遵循了他们的设置程序?是的,一切正常。不幸的是,Dropbox不起作用,拒绝您访问,但您的代码看起来正常。你是否正确地遵循了他们的设置程序?是的,一切正常。不幸的是,它不起作用