安卓:获取文件的Uri从内容乌里? [英] Android: Getting a file Uri from a content Uri?

查看:139
本文介绍了安卓:获取文件的Uri从内容乌里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在我的应用程序的用户选择音频文件,该文件的应用程序,然后处理。我遇到的问题是,为了让应用程序做我想要它做的音频文件,我需要的开放的我们要在文件格式。当我使用Android的原生音乐播放器,浏览应用程序中的音频文件,URI是一个内容URI,它看起来是这样的:

So in my app the user is to select an audio file which the app then handles. The problem I am having is that in order for the app to do what I want it to do with the audio files, I need the Uri to be in file format. When I use Android's native music player to browse for the audio file in the app, the Uri is a Content uri, which looks like this:

内容://媒体/外部/音频/媒体/ 710

然而,使用流行的文件管理器应用天文,我得到如下:

However, using the popular file manager application Astro, I get the following:

文件:///sdcard/media/audio/ringtones/GetupGetOut.mp3

后者是更接近我一起工作,但我当然希望该应用的功能与用户选择,无论他们使用的浏览他们的收藏节目的音频文件。所以我的问题是,有没有办法的内容转换://风格乌里到一个文件:// URI?否则,你有什么建议给我解决这个问题?这里是code的调出选择器,以供参考:

The latter is much more accessible for me to work with, but of course I want the app to have functionality with the audio file the user chooses regardless of the program they use to browse their collection. So my question is, is there a way to convert the content:// style Uri into a file:// Uri? Otherwise, what would you recommend for me to solve this problem? Here is the code which calls up the chooser, for reference:

Intent ringIntent = new Intent();
            ringIntent.setType("audio/mp3");
            ringIntent.setAction(Intent.ACTION_GET_CONTENT);
            ringIntent.addCategory(Intent.CATEGORY_OPENABLE);
            startActivityForResult(Intent.createChooser(ringIntent, "Select Ringtone"), SELECT_RINGTONE);

非常感谢你!请让我知道,如果我可以提供更多的code,以帮助回答。

Thank you very much! Please let me know if I can provide more code to help with answering.

我做的与内容开放的以下内容:

I do the following with the content Uri:

m_ringerPath = m_ringtoneUri.getPath(); 档案文件=新的文件(m_ringerPath);

m_ringerPath = m_ringtoneUri.getPath(); File file = new File(m_ringerPath);

届时,有些人的FileInputStream的东西与所述文件。

Then some FileInputStream stuff with said file.

推荐答案

只需使用 getContentResolver()。openInputStream(URI)来获得的InputStream 从URI。

Just use getContentResolver().openInputStream(uri) to get an InputStream from a URI.

<一个href="http://developer.android.com/reference/android/content/ContentResolver.html#openInputStream%28android.net.Uri%29">http://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net.Uri)

这篇关于安卓:获取文件的Uri从内容乌里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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