在我的应用程序中,用户将选择应用程序随后处理的音频文件.问题是,为了让应用程序按照我想要的方式处理音频文件,我需要URI为文件格式.当我使用Android的原生音乐播放器在应用程序中浏览音频文件时,URI是一个内容URI,如下所示:
content://media/external/audio/media/710
Run Code Online (Sandbox Code Playgroud)
但是,使用流行的文件管理器应用程序Astro,我得到以下内容:
file:///sdcard/media/audio/ringtones/GetupGetOut.mp3
Run Code Online (Sandbox Code Playgroud)
后者对我来说更容易使用,但当然我希望应用程序具有用户选择的音频文件的功能,而不管他们用来浏览他们的集合的程序.所以我的问题是,有没有办法将content://样式URI转换为file://URI?否则,你会建议我解决这个问题?以下是调用选择器的代码,供参考:
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);
Run Code Online (Sandbox Code Playgroud)
我使用内容URI执行以下操作:
m_ringerPath = m_ringtoneUri.getPath();
File file = new File(m_ringerPath);
Run Code Online (Sandbox Code Playgroud)
然后用所述文件做一些FileInputStream.
我正试图从画廊获取图像.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select picture"), resultCode );
Run Code Online (Sandbox Code Playgroud)
从这个活动返回后,我有一个包含Uri的数据.看起来像:
content://media/external/images/1
Run Code Online (Sandbox Code Playgroud)
如何将此路径转换为真实路径(就像' /sdcard/image.png')?
谢谢
我想从URI获取完整的文件路径.URI不是图像,但它是一个音乐文件,但如果我像MediaStore解决方案一样,如果应用程序用户选择例如Astro作为浏览器而不是音乐播放器,它将无法工作.我该如何解决这个问题?
在一个Activity中,我可以从Gallery中选择一个图像,我需要它的Uri路径(在日志中,我的测试图像的Uri路径是/content:/media/external/images/media/1).
我收到这个错误但是:
08-04 02:14:21.912: DEBUG/PHOTOUPLOADER(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory)
08-04 02:14:32.124: WARN/System.err(576): java.io.FileNotFoundException: /content:/media/external/images/media/1 (No such file or directory)
Run Code Online (Sandbox Code Playgroud)
这是文件路径的正确格式吗?或者我应该做到这样sdcard\...\image.png吗?
我正在尝试使用SHARE INTENTAndroid从Facebook,Twitter等分享图像.
我找到了将图像发送到共享意图的代码,但是这段代码需要位图的URI: fullSizeImageUri
这是完整的代码:
private void startShareMediaActivity(Bitmap image) {
boolean isVideo=false;
String mimeType="bmp";
Uri fullSizeImageUri=null;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, fullSizeImageUri);
try {
startActivity(Intent.createChooser(intent, (isVideo ? "video" : "image")));
} catch (android.content.ActivityNotFoundException ex) { }
}
Run Code Online (Sandbox Code Playgroud)
请问有人可以帮我将Bitmap转换为Uri吗?
谢谢
我有一个uri(java.net.URI),如http://www.example.com.如何在Java中将其作为流打开?
我真的必须使用URL类吗?
根据FileProvider 文档,该fileProvider.openFile()方法返回
一个新的ParcelFileDescriptor,您可以使用它访问该文件。
我查看了ParcelFileDescriptor,但我看不到如何访问该文件。那么如何从 ParcelFileDescriptor 访问文件呢?
我有一个android.net.URI对象(在MediaStore.ACTION_VIDEO_CAPTURE之后由onActivityResult返回的那种):它看起来像content:// media/video/media/33.
我想将它转换为File对象,只有一个File对象 - 我需要将它传递给另一个需要File的构造函数.
如何将这样的URI转换为File对象?如果我试试
File newFile = new File(myURI);
Run Code Online (Sandbox Code Playgroud)
我在Eclipse中收到错误,建议我将URI转换为String.在构造函数中提供URI.getPath()也没有帮助.
这涉及' 如何将android.net.uri对象转换为java.net.uri对象?'问题,遗憾的是似乎没有好的答案,但我想要一个File对象,而不是java uri.
我不介意我是否必须将它写入字节流并再次返回 - 无论什么是最好的方法.
如果我在交叉发布我自己的问题,请道歉,但我想我可能需要让事情更清楚一些.
我想在我的 android 应用程序中打开一个 .pdf 文件。现在我可以浏览 pdf 文件,浏览文件后,当我检查文件是否存在时,我收到文件未找到错误。现在选择文件后,我选择的文件 Uridata.getData()就像
content://com.android.externalstorage.documents/document/6333-6131:SHIDHIN.pdf
我解析使用时的路径data.getData().getPath().toString()就像
/document/6333-6131:SHIDHIN.pdf这是我的代码。请帮我。
// To Browse the file
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
startActivityForResult(intent, PICK_FILE_REQUEST);
Run Code Online (Sandbox Code Playgroud)
选择文件后
//onActivityResult
public void onActivityResult(final int requestCode, int resultCode, Intent data) {
try {
switch (requestCode) {
case PICK_FILE_REQUEST:
if (resultCode == RESULT_OK) {
try {
Uri fileUri = data.getData();
String path = fileUri.getPath().toString();
File f = new File(path);
if (f.exists()) {
System.out.println("\n**** Uri :> "+fileUri.toString());
System.out.println("\n**** Path :> …Run Code Online (Sandbox Code Playgroud) 我正在尝试将图像上传到php,因为我需要将文件发送到服务器.所以我试图从data参数创建一个文件.
但我得到了这个错误 Cannot resolve constructor File
这是我的代码:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
// Get the url from data
Uri selectedImageUri = data.getData();
if (null != selectedImageUri) {
// File
File imageFilePath = new File(selectedImageUri);
Run Code Online (Sandbox Code Playgroud)