2

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

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

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

录音机功能: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.");
            }
        }
    });   

上传功能:

否则如果(请求代码 == 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();
    }
4

1 回答 1

1

根据现场给出的官方示例。我希望这能帮到您。

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) {}
    }
}
于 2013-02-09T13:30:08.120 回答