首页 > 解决方案 > 如何在 android 中将特定的 SQLITE 音频文件共享到 Gmail?

问题描述

我正在使用录音应用程序,其中音频被记录并存储在应用程序中,并且该路径存储在 SQLITE 中。

我需要将该音频文件共享到 whatsapp/gmail 或保存在移动设备的内部目录中。

我尝试使用 Intent 分享它们,但在 whatsapp 中显示不支持的格式。

我试过这段代码

    private void Shareoption(List<RecordData> uploadlist)
{
    RecordData reco2 = uploadlist.get(0);
    String id3 = reco2.getId();
    final RecordData recordData = DBcreatedata.getData(id3);
    final File f;
    locname =   recordData.getRecordDataTitle();
    f = new File(recordData.getRecordData());

    Uri uri = Uri.parse(f.getAbsolutePath() );
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("audio/*");
    share.putExtra(Intent.EXTRA_STREAM, uri.toString());
    startActivity(Intent.createChooser(share, "Share Sound File"));

我也搜索了这个,我知道首先音频文件必须存储在内部目录中才能共享。所以我尝试了输入输出流的方法,它不起作用。

谁能帮我分享这个音频文件?

标签: androidandroid-intentandroid-sqliteshareaudio-recording

解决方案


通过使用它,我认为您的问题将得到解决

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri shareFileUri= Uri.parse(string);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
sharingIntent.setType("*/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, shareFileUri);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(Intent.createChooser(sharingIntent, "Share Sound File"));

推荐阅读