赞
踩
package com.zhangyu.mysysrecorder; import android.content.Intent; import android.os.Bundle; import android.provider.MediaStore; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private TextView tvRecorder; private final int REQUEST_CODE = 111; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { tvRecorder = (TextView) findViewById(R.id.tvRecorder); tvRecorder.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //设置intent的属性为录音设置 Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); startActivityForResult(intent, REQUEST_CODE); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { //请求 if (requestCode == REQUEST_CODE) { //得到录音的音频文件及路径 String dataFile = data.getDataString(); Log.d(TAG, "dataFile: " + dataFile); } } } }
2019-12-22 17:19:24.729 16758-16758/com.zhangyu.mysysrecorder D/MainActivity: dataFile: content://media/external/file/1205670
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。