2013-07-31 67 views
2

我正在开发一个应用程序,必须通过WhatsApp共享一个MP3文件。分享mp3通过whatsapp,Android

我在这一刻代码如下:

final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
shareIntent.setType("audio/mp3"); 
shareIntent.setPackage("com.whatsapp"); 
Uri recurso = Uri.parse("android.resource://com.yayo.yayobotonera/" + R.raw.audio1); 
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, recurso); 
startActivity(Intent.createChooser(shareIntent, getString(R.string.text1))); 

我可以成功地通过Gmail共享,例如,但它不是通过WhatsApp的工作。这是我的代码问题,或者只是说whatsapp不允许你共享MP3文件?

在此先感谢!

+0

什么样的错误呢上面的代码给你? – KOTIOS

+0

http://stackoverflow.com/questions/17996353/share-raw-resource-via-whatsapp/17997255#17997255 – filippo

回答

0

使用该::

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, ""));