gpt4 book ai didi

android - 通过 WhatsApp 共享原始资源

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:09 26 4
gpt4 key购买 nike

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

上面的代码在 Gmail 上运行良好,而 Whatsapp 会给出一个 toast 消息,例如“共享文件失败,请重试”

也许我和这个人有同样的问题:Intent.ACTION_SEND Whatsapp

但是我怎样才能把我的资源暂时复制到sd卡上,然后共享呢?

最佳答案

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;

list :

<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
...
</manifest>

关于android - 通过 WhatsApp 共享原始资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17996353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com