gpt4 book ai didi

java - 如何使用 android 将我录制的音频上传到 dropbox?

转载 作者:行者123 更新时间:2023-11-30 11:35:59 26 4
gpt4 key购买 nike

现在我正在创建基于 android 和 dropbox 的应用程序。

我想根据我的 api key 将我录制的音频上传到保管箱,但我已经尝试了很多。我找不到解决方案,所以任何人都可以帮助我克服这种情况。

这是我的代码。我在这段代码的帮助下完成了图像捕获和视频捕获。代码工作正常但是当我转换到我的录音机时它不起作用。谢谢回复。

录音功能:mAudio=(Button)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.");
}
}
});

上传函数:

else 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();
}

最佳答案

根据 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) {}
}
}

关于java - 如何使用 android 将我录制的音频上传到 dropbox?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14788402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com