首页 > 解决方案 > 从 url 共享音频文件

问题描述

我想从一个 url 共享一个音频文件(url 是 audio.getUrl())我试图先下载文件然后共享它但是当我在我的智能手机中尝试时它关闭了应用程序。你能告诉我任何其他方法吗?请帮忙。

 DownloadManager downloadManager = (DownloadManager) v.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
            Uri uri = Uri.parse(audio.getUrl());
            DownloadManager.Request request = new DownloadManager.Request(uri);
            request.setAllowedNetworkTypes(
                    DownloadManager.Request.NETWORK_WIFI
                            | DownloadManager.Request.NETWORK_MOBILE)
                    .setDestinationInExternalPublicDir("/sdcard/download/", "audio.mp3");
            downloadManager.enqueue(request);

            Intent compartirAudio = new Intent(android.content.Intent.ACTION_SEND);
            compartirAudio.setType("audio/*");
            compartirAudio.putExtra(Intent.EXTRA_STREAM,Uri.parse("/sdcard/download/audio.mp3"));
            v.getContext().startActivity(Intent.createChooser(compartirAudio, "Share"));

标签: javaandroid

解决方案


推荐阅读