【问题标题】:Share audio file (.mp3) via Facebook, email, and SMS/MMS通过 Facebook、电子邮件和 SMS/MMS 共享音频文件 (.mp3)
【发布时间】:2011-12-19 07:06:00
【问题描述】:

我有一个音频文件 (.mp3) 和一些相关信息。我想与 Facebook、电子邮件、SMS/MMS 等分享。

我所做的是:当用户点击分享按钮时,它会弹出所有可以处理这个 Intent 的受支持应用程序的列表。但这并没有显示 Facebook 和 SMS/MMS 选项。

这是我的代码..

public void shareWithFriends(int resId)
{
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("audio/mp3");
    share.putExtra(Intent.EXTRA_SUBJECT,"Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
    share.putExtra(Intent.EXTRA_TEXT,"Ringtone File : "+getResources().getResourceEntryName(resId)+".mp3");
    share.putExtra(Intent.EXTRA_STREAM,Uri.parse("android.resource://com.my.android.soundfiles/"+resId));
    share.putExtra("sms_body","Ringtone File : "+ getResources().getResourceEntryName(resId)+".mp3");
    startActivity(Intent.createChooser(share, "Share Sound File"));
}

以下是一些结果:

  1. 当我使用 MIME 类型 audio/mp3 时,只会弹出电子邮件选项。没有 Facebook 和 SMS/MMS 共享。

  2. 当我使用 MIME 类型 */* 时,会弹出电子邮件和 SMS 选项。没有 Facebook 选项。

这里有趣的是,当我单击 SMS 选项时,只显示文本。我没有看到任何 MP3 文件附件(同样的事情发生在 Whatsapp 中(因为我的手机上安装了 Whatsapp)。但是,当我点击任何邮件应用程序时(例如,Gmail 或 Yahoo 邮件)它会显示附加的 MP3 文件。

我哪里错了?

【问题讨论】:

    标签: android facebook audio facebook-graph-api share


    【解决方案1】:

    您正在尝试通过不支持它的服务共享 mp3。

    • Facebook 支持文字、图片和视频。
    • 短信是纯文本(而且只有很短的纯文本)
    • MMS 确实支持音频,但(据我观察(即没有阅读规范)我可以看出)仅支持比特率极低的音频,并且某些格式通常包含在扩展名为 .3g 的文件中

    这些应用未显示在支持 mp3 的应用列表中,因为它们不受支持

    【讨论】:

    • 感谢您的快速回复。所以最终结果就像“我无法将我的音频文件分享到 Facebook。”
    • 不使用他们的标准界面。通过应用程序可能会使其成为可能。可能值得研究一下 AudioBoo。
    • 我看到 Whatsapp 选项,但是当我选择该应用程序时,它不会附加我的音频文件。这可能是什么原因。但是,当我选择任何邮件应用程序(Gmail 或 YahooMail)时,我会看到附件,并且我再次可以看到邮件发送时带有必要的附件。
    【解决方案2】:

    Facebook 没有选项,但您可以通过蓝牙共享电子邮件和彩信。这是我的代码。看看对你有没有帮助:

    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("audio/*");
    share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///"+mypath));
    startActivity(Intent.createChooser(share, "Share Sound File"));
    break;
    

    这里我的路径是SD card上的声音文件的路径。

    【讨论】:

    • 不要使用固定路径..使用 getExternalStorageDirectory();而不是 "file:///"+mypath...
    • Uri.parse("file:/// 是共享意图所必需的.....是的 getExternalStorageDirectory() 可用于获取文件路径
    • 我的错误是“文件未知文件未发送”。我尝试使用蓝牙发送
    【解决方案3】:

    你要试试这个。

     final Intent sendIntent  = new Intent(Intent.ACTION_SEND);
                sendIntent.putExtra("sms_body", "bod of sms");
                sendIntent.setType("*/*");
                sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
                final File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.amr");
                Uri uri = Uri.fromFile(file1);
                Log.e("Path", "" + uri);
                sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(Intent.createChooser(sendIntent, ""));
    

    【讨论】:

      【解决方案4】:

      使用下面的代码,我可以通过意图共享音频。

      String path = Environment.getExternalStorageDirectory()
                      .getAbsolutePath() + "/abc.mp3";
      
      
              Intent share = new Intent(Intent.ACTION_SEND);
              share.setType("audio/*");
              share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + path));
              startActivity(Intent.createChooser(share, "Share Sound File"));
      

      【讨论】:

        【解决方案5】:
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("audio/*");
                sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,
                        Uri.fromFile(new File("filepath")));            
                startActivity(Intent.createChooser(sharingIntent,"Share using"));
        

        【讨论】:

          【解决方案6】:
          String sharePath = Environment.getExternalStorageDirectory().getPath()
              + "/Soundboard/Ringtones/custom_ringtone.ogg";
          Uri uri = Uri.parse(sharePath);
          Intent share = new Intent(Intent.ACTION_SEND);share.setType("audio/*");
          share.putExtra(Intent.EXTRA_STREAM, uri);
          startActivity(Intent.createChooser(share, "Share Sound File"));
          

          【讨论】:

            【解决方案7】:
            File f=new File("full audio path");
            Uri uri = Uri.parse("file://"+f.getAbsolutePath());
            Intent share = new Intent(Intent.ACTION_SEND);
            share.putExtra(Intent.EXTRA_STREAM, uri);
            share.setType("audio/*");
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            context.startActivity(Intent.createChooser(share, "Share audio File"));
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2018-07-04
              • 1970-01-01
              • 2023-03-07
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多