Android 通过WhatsApp共享原始资源
上面的代码在Gmail上运行良好,而Whatsapp提供了一条toast消息,如“共享文件失败,请重试” 也许我和这家伙有同样的问题: 但是,我如何在sd卡上临时复制我的资源,然后共享它们呢Android 通过WhatsApp共享原始资源,android,android-intent,resources,share,whatsapp,Android,Android Intent,Resources,Share,Whatsapp,上面的代码在Gmail上运行良好,而Whatsapp提供了一条toast消息,如“共享文件失败,请重试” 也许我和这家伙有同样的问题: 但是,我如何在sd卡上临时复制我的资源,然后共享它们呢 Intent share = new Intent(Intent.ACTION_SEND); share.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + ContextID.getPackageName() + "/" + Re
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://" + ContextID.getPackageName() + "/" + ResourceID));
share.setType("audio/*");
ContextID.startActivity(Intent.createChooser(share, "Condividi il suono"));
舱单:
File dest = Environment.getExternalStorageDirectory();
InputStream in = ContextID.getResources().openRawResource(ResourceID);
try
{
OutputStream out = new FileOutputStream(new File(dest, "lastshared.mp3"));
byte[] buf = new byte[1024];
int len;
while ( (len = in.read(buf, 0, buf.length)) != -1)
{
out.write(buf, 0, len);
}
in.close();
out.close();
}
catch (Exception e) {}
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory().toString() + "/lastshared.mp3"));
share.setType("audio/*");
ContextID.startActivity(Intent.createChooser(share, "Condividi il suono \"" + TheButton.getText() + "\""));
return true;
...
请更改代码中的这一行,您就可以共享了
将(“音频/mp3”)
改为下面的(“音频/*”)
这是因为whatsapp的共享类型不支持
(“*/*”)或(“*/*”)或(“*/*”)您好,我正在使用您的代码通过whatsapp发送mp3
文件,但我收到类似于发送失败的错误,请重试。你知道如何克服这个问题吗?提前谢谢它的工作。如果你试图直接从资产中分享,whatsapp将不允许你。Grazie Mille!!干得好;)您不需要写入外部存储,因为它可以通过内容提供商完成。通过内容提供商共享您的文件,而不是保存在外部存储器中,然后共享
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
...
</manifest>
share.setType("audio/mp3");