2017-02-19 75 views
0

我有res/raw/suono1.mp3中的音频mp3,我需要在whatapp上共享(在我的应用程序中)我的代码是它,但是当我发送时,不要共享HELP ME PLS。为Android工作室在内部存储器中保存文件android为我的应用程序

pulsante2.setOnLongClickListener(new View.OnLongClickListener() { 
@Override 
public boolean onLongClick(View v) { 

    //condividere 
    InputStream inputStream; 
    FileOutputStream fileOutputStream; 
    try { 
      inputStream = getResources().openRawResource(R.raw.suono2); 
      fileOutputStream = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "sound.mp3")); 
      byte[] buffer = new byte[1024]; 
      int length; 
      while ((length = inputStream.read(buffer)) > 0) { 
       fileOutputStream.write(buffer, 0, length); 
      } 

      inputStream.close(); 
      fileOutputStream.close(); 

     } 
    catch (IOException e) { 
       e.printStackTrace(); 
      } 

      Intent intent = new Intent(Intent.ACTION_SEND); 
      intent.putExtra(Intent.EXTRA_STREAM, 
        Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/sound.mp3")); 
      intent.setType("audio/mpeg"); 
      startActivity(Intent.createChooser(intent, "Share audio")); 

      return false; 
     } 
}); 

发送代码我需要他们

+2

这很好,只要你在应用程序的私有内存中工作,但是如果你想尝试类似** Environment.getExternalStorageDirectory()(不再是你的私有应用程序内存)**,调试日志和发布例外将进一步帮助你和其他人了解你的问题 – ShayHaned

+0

我有原始音频可以为我的应用程序代码?我不会说英语很好,但我没有足够的代码,我需要共享一个audio.mp3从我的应用程序到Whatapp –

+0

从YourApp分享到WhatsApp对任何人都不是问题,除了帐户。因此,一旦您开始通过代码嗅探WhatsApp的帐户访问权限和可修改性规则,这就是创建漏洞漏洞的地方。所以WhatsApp通过** WhatsApp第三方集成填补了这些漏洞,并且WhatsApp Api Usage仅仅被禁止**。也许你正试图将原始声音写入WhatsApp文件夹?如果您正在寻找将声音存储在WhatsApp文件夹中,这是您可以做的事情,但您无法以编程方式通过WhatsApp或通过WhatsApp播放媒体! – ShayHaned

回答

0

你问权限在manifest.xml文件?

+0

yes

相关问题