如何使用正确的文件名 Intent.ACTION_SEND? [英] How to Intent.ACTION_SEND with correct file name?

查看:86
本文介绍了如何使用正确的文件名 Intent.ACTION_SEND?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要共享音频(音乐)文件,但是当我使用以下代码时,我得到了不同名称的文件,这不好.因为它是音乐文件,所以我需要保留所有属性,如艺术家、标题和文件名.有什么办法吗?

I need to share audio (music) file, but when I use following code, I got file with different name, which is not good. Because it is music file, I need to keep all atributes, like artist, title and name of file. Is there any way how to do it?

        final String filePath = "/storage/emulated/0/Music/music.mp3";
        final Intent intentShareFile = new Intent(Intent.ACTION_SEND);
        intentShareFile.setType("audio/*");
        intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse(filePath));
        context.startActivity(Intent.createChooser(intentShareFile,"Share"));

我正在使用 WhatsApp 进行测试.

I am using WhatsApp for testing.

推荐答案

试试这个:

 packageName = getIntent().getStringExtra("topPackageName");
 String audioName = arrAudio.get(position).getAudioFileName();
                File audioFile = new File(Environment.getExternalStorageDirectory() + "/EmoticApp/AudioFile/" + audioName);

                Uri audioUri = Uri.fromFile(audioFile);
                Intent audioIntent = new Intent(Intent.ACTION_SEND);
                audioIntent.setType("audio/*");
                audioIntent.putExtra(Intent.EXTRA_STREAM, audioUri);
                audioIntent.setPackage(packageName);
                startActivity(audioIntent);

这篇关于如何使用正确的文件名 Intent.ACTION_SEND?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆