2013-02-09 40 views
2

现在我正在创建基于android和dropbox的应用程序。如何使用android将我录制的音频上传到Dropbox?

我想上传我录制的音频在Dropbox基于我的API密钥,但我已经尝试了很多。我无法找到解决方案,所以任何人都可以帮助我克服这种情况。

这是我的代码。借助此代码,我完成了图像捕获和视频捕获。该代码工作正常,但是当我转换成我的录音机它does not工作。谢谢回复。

录音功能: mAudio =(Button)findViewById(R.id.audio_button); mAudio.setOnClickListener(新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."); 
      } 
     } 
    }); 

上传功能:

否则,如果(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

请访问我的标题评论我有 更新。谢谢回复。 – user2057085 2013-02-10 08:41:13

回答

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) {} 
    } 
} 
+0

@ user2057085检查我的答案.. – Rahil2952 2013-02-09 13:30:36