现在我正在创建基于android和dropbox的应用程序。
我想根据我的api键在Dropbox上传我录制的音频,但我已经尝试了很多。我无法找到解决方案,所以任何人都可以帮助我克服这种情况。
这是我的代码。借助此代码,我完成了图像捕获和视频捕获。代码工作正常,但当我转换成我的录音机它不起作用。谢谢回复。
录音功能: mAudio =(按钮)findViewById(R.id.audio_button); mAudio.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent();
// Picture from camera
intent.setAction(Audio.Media.RECORD_SOUND_ACTION);
Uri fileUri = getOutputMediaFileUri(MEDIA_TYPE_AUDIO);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, fileUri);
Log.i(TAG, "Importing New Picture: " + mCameraFileName);
try {
startActivityForResult(intent, NEW_AUDIO);
} catch (ActivityNotFoundException e) {
showToast("There doesn't seem to be a camera.");
}
}
});
上传功能:
否则if(requestCode == NEW_AUDIO){
if (resultCode == Activity.RESULT_OK) {
Uri uri = null;
if (data != null) {
uri = data.getData();
}
if (uri == null && mAudioFileName != null) {
uri = Uri.fromFile(new File(mAudioFileName));
Log.v("Audio Uri", uri.toString()+" "+uri.getPath());
}
File file = new File(mAudioFileName);
Log.v("Audio file", ""+file.getPath());
if (uri != null) {
UploadFile upload = new UploadFile(Home.this, mApi, PHOTO_DIR, file);
upload.execute();
}
//showToast("till capture");
}
else if(resultCode == RESULT_CANCELED)
{
uriAudio = null;
Toast.makeText(Home.this,"Cancelled!",Toast.LENGTH_LONG).show();
}
答案 0 :(得分:1)
根据site给出的官方示例。我希望这会对你有所帮助。
FileInputStream inputStream = null;
try {
File file = new File("/path/to/file.txt");
inputStream = new FileInputStream(file);
Entry newEntry = mDBApi.putFile("/testing.txt", inputStream,
file.length(), null, null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
} catch (DropboxUnlinkedException e) {
// User has unlinked, ask them to link again here.
Log.e("DbExampleLog", "User has unlinked.");
} catch (DropboxException e) {
Log.e("DbExampleLog", "Something went wrong while uploading.");
} catch (FileNotFoundException e) {
Log.e("DbExampleLog", "File not found.");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {}
}
}