android MediaStore.Audio.Media.RECORD_SOUND_ACTION:找不到处理意图的活动

时间:2013-03-21 11:19:45

标签: android android-intent event-handling record audio

我尝试录制声音。我使用Intent来录制声音。但是在一台设备上MediaStore.Audio.Media.RECORD_SOUND_ACTION返回错误:

这是我的代码:

Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, RQS_RECORDING);

这是我的错误:

No activity found to handle Intent { act=android.provider.MediaStore.RECORD_SOUND (has extras) }

可能是什么原因?这是否意味着某些设备无法访问该功能? 如何检查设备上是否存在RECORD_SOUND_ACTION?

2 个答案:

答案 0 :(得分:2)

也许该设备没有任何允许您录制音频的应用程序。首先检查它是否有默认的录音机。

根据另一篇文章(Samsung Charge RECORD_SOUND_ACTION Intent not returning when started for result),它也可能发生在其他设备上,可能是一个错误。

即使您的设备具有默认录音机,如果该应用程序不包含 RECORD_SOUND_ACTION 意图的接收器,也未在其清单中声明将处理指定的意图。

你可以通过实现自己的录音机来处理这个意图,并以这种方式在你的清单中声明它(以防你想要):

<activity
    android:name="com.test.AudioRecorder"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.provider.MediaStore.RECORD_SOUND" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

答案 1 :(得分:1)

从文件中试用此代码可能会帮助您解决问题

try 
{
     Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
     File file = new File(image.getAbsolutePath());
     String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
     String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);

     myIntent.setDataAndType(Uri.fromFile(file), mimetype);
     mContext.startActivity(myIntent);
} 
catch (Exception e) 
{
     // TODO: handle exception
     String data = e.getMessage();
}